Executing Javascript written with XMLHttpRequest that contains script tags?

Through a Javascript request, XMLHttpRequest responds with some additional Javascript that needs to be executed on the requesting page.

Using eval(), if the response is something like:

    alert('This is the js response');

... then this works just fine.

However, the text returned will look something like this:

<script language="javascript">var checkVar='checkVar: value 1';</script>

I have ensured that the XMLHttpRequest is synchronous, as I want to reference checkVar right after this.

So:

    <script type="text/javascript" src="http://www.mysite.com/setCheckVar.js" />

    <script type="text/javascript" >
        alert('checkVar');
    </script>

The alert message should read "checkVar: value 1".

For other reasons, this is not just as simple as setting *var checkVar* in setCheckVar.js, so I'm not looking for that kind of recommendation.  

I suppose that I could strip out the beginning and ending script tags and keep the eval() way of doing it.  However, I would like to know if there are any solutions that support what I'm looking for?


Thanks.


Executing Javascript written with XMLHttpRequest that contains script tags?
===


Through a Javascript request, XMLHttpRequest responds with some additional Javascript that needs to be executed on the requesting page.

Using eval(), if the response is something like:

    alert('This is the js response');

... then this works just fine.

However, the text returned will look something like this:

<script language="javascript">var checkVar='checkVar: value 1';</script>

I have ensured that the XMLHttpRequest is synchronous, as I want to reference checkVar right after this.

So:

    <script type="text/javascript" src="http://www.mysite.com/setCheckVar.js" />

    <script type="text/javascript" >
        alert('checkVar');
    </script>

The alert message should read "checkVar: value 1".

For other reasons, this is not just as simple as setting *var checkVar* in setCheckVar.js, so I'm not looking for that kind of recommendation.  

I suppose that I could strip out the beginning and ending script tags and keep the eval() way of doing it.  However, I would like to know if there are any solutions that support what I'm looking for?


Thanks.

