【发布时间】:2013-09-16 13:03:44
【问题描述】:
为了了解正在发生的事情,可能会四处寻找。 这是我的 jquery ajax 请求:
function newContact() {
$.ajax({
type: 'POST',
contentType: 'application/json',
// url: rootURL,
url: "http://xxxxxxxxx.xxxxx/api/det",
dataType: "json",
//data: formToJSON(),
data: '{"name":"tom","last":"test","email":"test@west.coast.com","password":"xyz"}',
success: function(data, textStatus, jqXHR){
alert('Welcome');
},
error: function(jqXHR, textStatus, errorThrown){
console.log(' Error: ' + errorThrown);
}
});
}
现在,我用 curl 测试了 url 并且它有效,我检查了输入的 val() 是否被填充,它确实如此,我真的不明白为什么当我触发函数时我得到一个 GET 请求如下:
[11:08:47.607] GET http://xxxxx.com/?name=&last=&email=test%40email.test.com&passwrd=asdf&passwrd2= [HTTP/1.1 304 Not Modified 40ms]
这是发送到服务器的内容。现在,如果我打开 firebug 的控制台,我会看到以下内容:
POST http://xxxxxxxxxxx.com/api/det
jquery.min.js (line 6)
HeadersPost
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length 81
Content-Type application/json; charset=UTF-8
Host xxxxxxx.com
Referer http://xxxxxxxxx.com/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
X-Requested-With XMLHttpRequest
我真的无法理解。当 apache 收到 GET req 时,上面提到的这个 POST 是什么?
此外,作为一个 ajax/json 的新手,我不知道可能是什么问题或如何开始故障排除。
任何可以在这里阐明一些想法的想法将不胜感激。
编辑 现在感谢this,我已经能够向前迈出一小步:在将方法 post 添加到表单后,我已经能够发出 post 请求,但是它转到 / 而不是我期望的位置(url : "http://xxxxxxxxx.xxxxx/api/det")。
【问题讨论】:
-
函数是如何触发的?它在事件处理程序中吗?
-
我认为same origin policy违规
-
该函数由jquery点击函数触发: $("#subm").button({icons: {primary: "ui-icon-person"}}).click(function() { newContact(); });
标签: javascript jquery ajax json http-post