2017-02-07 39 views
0

AJAX如何用於在單獨的html頁面上執行代碼?AJAX調用例程不執行

在一個調用頁面我的代碼

$.ajax({ 
    url: 'ajaxcalled2.html', //This is the current doc 
    type: "POST", 
    async: 'false', 
dataType: 'json', 
    data: {username: "ABC123", season: "Winter", email: "[email protected]"}, 
    complete: function(response){ 
     console.log(response); 
    } 
}); 

在所謂的頁面我的代碼:

<html> 
<script type="text/javascript"> 
alert('here'); 
</script> 
</html> 

調用頁轉到完整的功能,所以不會出現成爲該頁面的問題

我可以調出被叫頁面,並且警報成功顯示。

但將它們放在一起,不顯示警報。

我錯過了什麼?

回答

0

測試不同的選項,選擇使用getscript選項。

在調用程序,它可以在被調用程序

用戶名=「MYNAME」訪問設置全局值;

$.getScript("http://<domain>/ajaxcalled.js", function(){ 

alert("Script loaded and executed."); 

}) 

的叫JS只是有

alert('hi'); 
alert(username); 

用戶名成功顯示。