如何通过AJAX发送表单数据时解决Firebug的“中止”消息?

时间:2016-04-05 06:20:36

标签: php ajax firebug

我已经创建了一个PHP Web应用程序并使用MySQL作为数据库后端,但是有一个' Aborted'访问网页时,请注意Firebug的 Net 面板的状态列。为什么呢?



 $('#submit').on('click', function () {
//        e.preventDefault();
        var formData = JSON.stringify($("#frmPayoye").serializeObject());
        console.log(formData);
        $.ajax({
            type: "POST",
 
            url: "http://www.sanaroopay.com/pg/api/ectransact/", 
            data: formData,
            cache: false,
            timeout: 60000,
            async: false,
            processData: true,
            dataType: 'json',   //you may use jsonp for cross origin request
            contentType: "application/json; charset=utf-8",
            crossDomain: true,            
            success: function (data) {
                alert(JSON.parse(data));
//                alert("ok");
                console.log("success");
//                window.location.assign('https://secure.payoye.net/web/merchant');
            },
            error: function () {
                console.log("Failed");
            }
        });
    });




2 个答案:

答案 0 :(得分:1)

您没有取消表单提交,因此Ajax调用已中止,页面按照设计要求提交表单。所以你需要停止表单提交。

$('#submit').on('click', function (evt) { 
    evt.preventDefault(); //stop the default action of the button
    //Rest of your code
});

答案 1 :(得分:-1)

  

请参阅XHR open()的文档,例如:https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest

     

注意:将此方法称为已经激活的请求(已经调用open()或openRequest()的请求相当于调用abort()。

     

只需在需要时创建一个新的XHR实例。更好的是,使用jQuery或其他JS库来执行AJAX。它应该保护你免受这些错综复杂的影响。

How to solve Firebug’s “Aborted” messages upon Ajax requests?

相关问题