我不确定这个请求有什么问题,但现在正在发生的事情......
浏览器似乎认为我正在发出跨域请求,但是我正在向请求来自的同一页面发出请求。
我调用了一个名为search的函数,我在google chrome dev控制台中将其返回
当我加载jquery-1.0.2.min.js时,会发生同样的事情 服务器返回:{“readyState”:4,“status”:404,“statusText”:“error”}
Bad request search.js?1383509337:48
POST http://example.com/transaction/search jquery-2.0.3.js:7845
x.support.cors.e.crossDomain.send jquery-2.0.3.js:7845
x.extend.ajax jquery-2.0.3.js:7301
search search.js?1383509337:22
(anonymous function) search.js?1383422028:17
x.event.dispatch jquery-2.0.3.js:4676
y.handle jquery-2.0.3.js:4360
function search(user, transactionDate, vendorField, amountField, accountField, departmentField, subDepartmentField, statusField, projectidField){
var url = "/transaction/search";
var ajax = jQuery.ajax({
type: 'POST',
dataType: 'json',
url: url,
data: {
user: user,
transactionDate: transactionDate,
vendorField: vendorField,
amountField: amountField,
accountField: accountField,
departmentField: departmentField,
subDepartmentField: subDepartmentField,
statusField: statusField,
projectidField: projectidField
},
beforeSend: function(data){
$('#searchSpinner').show();
console.log("Sending request");
},
success: function(data){
console.log("Successful request");
data = JSON.parse(data, true);
loadTransactions(data['response']['transactions']);
$('#searchSpinner').hide();
},
error: function(data){
console.log("Bad request");
$('body').html(JSON.stringify(data));
$('#searchSpinner').hide();
}
}).done(function(data){
console.log("finished");
$('#searchSpinner').hide();
});
}
答案 0 :(得分:1)
原来问题不在于AJAX请求,但是一个糟糕的MySQL查询占用了太多的资源时间和页面时间。