最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ajax XHR failed loading: POST - Stack Overflow

programmeradmin7浏览0评论

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.

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.

Share Improve this question edited Oct 27, 2016 at 6:39 Juan Salvador Portugal asked Oct 27, 2016 at 6:17 Juan Salvador PortugalJuan Salvador Portugal 1,3395 gold badges23 silver badges40 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 1

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./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"
});
发布评论

评论列表(0)

  1. 暂无评论