开发者

jQuery AJAX Load: Get a variable from loaded document

I would like to be able to set variables in a document and then through an AJAX load, get the values of the variable.

loadme.htm:

<html>
<head>
<script>
var test_variable='I need this variable in destination document'
</script>
</head>
<body>
HTML content that will also be loaded and placed in the destination document.
</body>
</html>

Destination Document:

 $.ajax({
     type: "GET",
     url: "loadme.htm",
     dataType: "html",
     success: function(html){
 开发者_Python百科       alert(test_variable)
        $('#destination').html(html)
     }
});

The above code obviously doesn't work. So... how would I be able to get the values of the variable that was established in the loaded document?

Thank you! :-)


Have you tried setting the content of #destination before attempting to alert test_variable? Jquery attempts to execute code if it finds script tags, and since test_variable is being declared in the global space, your success function should have access to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜