문서에서 변수를 설정하고 AJAX로드를 통해 변수 값을 가져오고 싶습니다.jQuery AJAX로드 :로드 된 문서에서 변수 가져 오기
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>
대상 문서 :
$.ajax({
type: "GET",
url: "loadme.htm",
dataType: "html",
success: function(html){
alert(test_variable)
$('#destination').html(html)
}
});
위의 코드는 분명히 작동하지 않습니다. 그렇다면 ... 어떻게로드 된 문서에 설정된 변수의 값을 얻을 수 있습니까?
감사합니다. :-)
음, 귀하의 게시물에 물음표가 표시되지 않습니다. – cheeken
왜 다른 페이지에서 변수를 가져와야합니까? 그냥 변수를 외부 js 파일에 포함하십시오 – Evan