XHR加载失败:POST
ajax XHR failed loading: POST
所以我试图用ajax发布,它只是不会通过。
这是我的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"
});
});
});
我没有得到一个错误,也不是我从ajax获得成功。但我得到一个chrome控制台错误上面列出的XHR加载失败:POST
有时帖子是正确的,有时我得到XHR加载失败:post
错误
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
对此事的任何帮助都非常感谢。
检查您的数据必须
类型:普通对象、字符串或数组,成功方法必须至少有一个参数
类型:函数(任何数据,字符串textStatus, jqXHR)
http://api.jquery.com/jquery.ajax/例子:
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"
});
相关文章:
- Python POST 请求失败
- 对php的Angular post请求失败
- Https XMLHttpRequest POST在本地主机上失败
- gwt使用本机javascript向远程服务器发送POST请求失败
- Jquery .clone() 导致 $.post 失败
- POST 请求失败,没有错误消息 (Parse.com / ExpressJS)
- 在 Couchdb ( 虹膜沙发 ) POST 请求中添加新文档失败,状态为 500
- php&ajax检索post数据失败
- 为什么onreadystatechange在尝试将数据POST到php脚本时失败
- 成功的$.Ajax和$.Post调用总是从C#返回失败
- .post()失败回调函数
- $http POST在AngularJS中失败,在google REST客户端中成功
- Ajax POST失败,但可以在控制台中工作
- Steam Post请求-加载资源失败:服务器的响应状态为400(错误请求)
- "错误“;或“;失败”;在jQuery中调用$.post Ajax
- POST方法即使if条件失败也能工作
- XHR加载失败:POST
- Angularjs的HTTP POST调用在部署中验证登录失败-返回400错误
- node.js中的POST失败
- $.post 失败,出现错误“..不是一个函数”