-1

If not, what would be a workaround?

Something like this:

Page 1:

<script>
  var test = '';

    *** AJAX Request to Page 2 ***

  document.write(test);
</script>

Page 2:

<script>test = "test Data";</script>
Paul
  • 139,544
  • 27
  • 275
  • 264
reformed
  • 4,505
  • 11
  • 62
  • 88

2 Answers2

1

Why not set the variable value in the callback of the ajax request? Something like this:

$.ajax({
    url: "test.html",
    context: document.body
}).done(function(res) {
    test = res.value;
});

The script from page 2 can return an JSON Object like {value: 'test Data'}

Remigius Kijok
  • 215
  • 2
  • 8
0

You can set variables with the page you request, if this page runs some javaScript. I assume your ajax request is calling page 2?

However, it would make more sense, I think, to set the variable in the callback of your ajax request.

Since you did not list any server side languages, I'm also assuming you are talking about changing client-side variables.