简体   繁体   中英

ajax XHR failed loading: 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.

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"
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM