2017-01-26 44 views
-1

這個阿賈克斯代碼有時只有工作。請解決我的問題:阿賈克斯偶爾工作

App.controller('sendemail', function (page) { 
    $.ajax({ 
     type: 'GET', 
     url: 'http://sanjuwebworks.com/content/9-mobileapps/sendemail.php?callback=response', 
     // data to be added to query string: 
     data: { name: 'Zepto.js' }, 
     // type of data we are expecting in return: 
     dataType: 'jsonp', 
     timeout: 300, 
     context: $('body'), 
     success: function(data){ 
     // Supposing this JSON payload was received: 
     // {"project": {"id": 42, "html": "<div>..." }} 
     // append the HTML to context object. 
     alert(data.success) 
     console.log('success',data) 
}, 
error: function(xhr, type){ 
alert('Ajax error!') 
} 
}) 

只有時它會提醒並記錄到控制檯,大多數情況下它不響應。

+0

刪除'timeout:300'並重試。 –

+0

是的,300ms超時是不現實的 –

+0

感謝球員,它消除了超時後 –

回答

0

您的ajax調用正在工作。如果直接從瀏覽器中調用的網址,您將收到此:

{success: false} 

由於您使用「GET」你可以添加&name=Zepto.js到URL,但答案是一樣的。

http://sanjuwebworks.com/content/9-mobileapps/sendemail.php?callback=response 

所以我會說你的PHP函數工作不正常。

編輯:但我從您的角度功能提取AJAX調用,並通過jQuery調用它。