weixin_33701294 2017-01-26 07:41 采纳率: 0%
浏览 2

Ajax偶尔工作

This ajax code is only working sometimes. Please solve my problem:

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!')
} 
})

Only sometimes it's alerting and logging to the console,mostly it does not respond.

  • 写回答

1条回答 默认 最新

  • weixin_33697898 2017-01-26 08:25
    关注

    Your ajax-call is working. If you call the URL directly from browser you will receive this:

    {success: false}
    

    Because you are using 'GET' you can add &name=Zepto.js to the URL, but the answer will be the same.

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

    So I would say that your PHP-function is not working correctly.

    EDIT: But I extracted the AJAX-call out of your angular-function and called it via jQuery.

    评论

报告相同问题?