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 01 Answer
Reset to default 1Check 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"
});