我有以下 jQuery AJAX 请求:
function addRecord() {
console.log('addRecord');
$.ajax({
type: 'POST',
url: rootURL,
contentType: 'application/json',
dataType: "json",
data: formToJSON(),
success: function(data, textStatus, jqXHR){
alert('form submitted successfully');
alert('data'+data);
},
error: function (xhRequest, ErrorText, thrownError) {
alert("Failed to process request correctly, please try again");
console.log('xhRequest: ' + xhRequest + "\n");
console.log('ErrorText: ' + ErrorText + "\n");
console.log('thrownError: ' + thrownError + "\n");
}
});
}
function formToJSON() {
return JSON.stringify({"dateofVisit": $('#dateofVisit').val()});
}
以下是我在 firebug 中收到的输出。
响应标头:
Server Apache-Coyote/1.1
Access-Control-Allow-Orig... *
Access-Control-Allow-Cred... true
Access-Control-Allow-Meth... GET, POST, DELETE, PUT, OPTIONS, HEAD
Access-Control-Allow-Head... Content-Type, Accept, X-Requested-With
Content-Type text/plain
Transfer-Encoding chunked
Date Thu, 24 Oct 2013 09:37:34 GMT
Connection close
Request Headersview source
Host localhost:8080
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/json; charset=UTF-8
Referer http://mydomain.com/DemoPurpose/demo.html
Content-Length 28
Origin http://mydomain.com
Pragma no-cache
Cache-Control no-cache
邮政:
JSON
dateofVisit
"23-10-2013"
Source
{"dateofVisit":"23-10-2013"}
回复:
empty
控制台输出:
xhRequest: [object Object]
ErrorText: error
thrownError:
我是 jquery 的新手,所以基本上不知道我在哪里做错了。有一件事是肯定它会出错的ajax调用的一部分,但为什么呢?它能够形成json ...那为什么它会出错?请帮我。