weixin_33728268 2016-10-27 06:17 采纳率: 0%
浏览 779

ajax XHR加载失败:POST

so I am trying to post with ajax, and it just wont go through.

here is my javascript

$.fn.serializeObject = function()
        {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function() {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };

        $(function() {
            $('#formulario').submit(function() {
                formData = JSON.stringify($('#formulario').serializeObject());
                console.log(formData);
                //return false;

                                    $.ajax({
              type: "POST",
              url: "http://localhost/teleinformatica/API/user/validarLogin",
              data: formData,
              success: function(data){console.log(data.msg);},
              error: function(){location.reload();},
              dataType: "json",
              contentType : "application/json"
            });


            });
        });

I am not getting an error nor am I getting a success from ajax. But I am getting a chrome console error listed above XHR failed loading: POST

sometimes the post is done correctly, and others i get XHR failed loading: POST

This is the error

XHR failed loading: POST 
"http://localhost/teleinformatica/API/user/validarLogin".
   send @ script/jquery.min.js:2
   ajax @ script/jquery.min.js:2
   (anonymous function) @ p2.php:89
   dispatch @ script/jquery.min.js:2
   u @ script/jquery.min.js:2

Any help on this matter really appreciated.

  • 写回答

1条回答 默认 最新

  • weixin_33744141 2016-10-27 06:31
    关注

    Check your data must be

    Type: PlainObject or String or Array & success method must have at least one argument

    Type: Function( Anything data, String textStatus, jqXHR jqXHR )

    http://api.jquery.com/jquery.ajax/ example :

    formData = {data1:"yourdata1", data2:1021};
    $.ajax({
        type: "POST",
        url: "http://localhost/teleinformatica/API/user/validarLogin",
        data: formData,
        success: function(data){console.log(data);},
       dataType: "json",
       contentType : "application/json"
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料