0

I have an ajax response which returns html and javascript as follows:

<div class="contents">
  <div>1</div>
  <script>
    var test = "test";
  </script>
</div>

How can I access the variable test?

Envious
  • 584
  • 1
  • 6
  • 20

1 Answers1

0

Append the response in some temp div, get the value from variable and remove the div.

$("<div id='dvTemp'></div>").html(AjaxResponse).appendTo("body");
alert(test);
$("#dvTemp").remove();
Rashmin Javiya
  • 5,173
  • 3
  • 27
  • 49