I have a AJAX request that will return a string that contains some HTML code:
The returned value is a very big string, like this:
</div></div>
<script type="text/javascript">
var bld=[{"stufe":7,"gid":"4","aid":"18"}]
</script>
<div id="map_details">< div class="movements">...
The only part I need is the variable bld inside that <script> tag.
I use jQuery in my script, but, since it evals every single piece of <script> code inside the ajax response, I had to use another AJAX method to return the complete string with the <script> tag on it…
I think this could have 2 solutions:
-
If the jQuery AJAX function
evalsthe script code inside the html response, how could I access the value of that variable?I have already tried but the variable
bldis undefined in theajax.successfunction. -
Is there a way to use javascript or jquery to get the variable that is inside that
< script>tag when I have that value in an html string?
You need to load the returned data into your DOM. It will then be parsed, the javascript will run, and the variable will be in global scope. You can do this in a hidden div if you don’t want to see all of the other stuff.
Is this not what you want?
Demo: http://jsfiddle.net/jtbowden/GZvG9/1/