[英]HTTP POST to CouchDB via Javascript/JQuery errors
Im trying to send a uttermost simple POST request to CouchDB in every possible way, but it wont work.. The database consists of documents with ID names of colors and a atribute with also the colorname (first in Dutch, the in English) and im trying to add a document. 我试图以各种可能的方式向CouchDB发送一个最简单的POST请求,但是它无法正常工作。该数据库由ID名称为color的文档组成,并且属性名称也为colorname(首先是荷兰语,英语是init)和im尝试添加文档。
$.ajax({
url: 'http://127.0.0.1:5984/colors',
type: "POST",
contentType: "application/json",
data: {"Kleur": "PURPLE"},
crossDomain: true,
success:function(response, status){
alert("*----Received Data----*\n\nResponse : " + response+"\n\nStatus : " + status);//"response" receives - whatever written in echo of above PHP script.
console.log("*----Received Data----*\n\nResponse : " + response+"\n\nStatus : " + status);
}
});
The code above gives me a 400 Bad Request error. 上面的代码给我一个400错误的请求错误。 Why i dont know.. When i did the POST request to posttestserver.com it says that there were no POST variables but the POST body was 12 chars long. 为什么我不知道..当我向posttestserver.com发出POST请求时,它说没有POST变量,但POST主体的长度为12个字符。
This is the other code i tried: 这是我尝试的其他代码:
$.post("http://127.0.0.1:5984/colors", //Required URL of the page on server
{ // Data Sending With Request To Server
contentType: 'application/json',
data: {"Kleur": "PURPLE"},
crossDomain: true,
},
function(response,status){ // Required Callback Function
alert("*----Received Data----*\n\nResponse : " + response+"\n\nStatus : " + status);//"response" receives - whatever written in echo of above PHP script.
console.log("*----Received Data----*\n\nResponse : " + response+"\n\nStatus : " + status);
});
This time i get a 415 Unsupported Mediatype error and when i POST to posttestserver.com it says it has 3 POST variables but no POST body anymore.. 这次我收到415 Unsupported Mediatype错误,当我开机自检到posttestserver.com时,它说它具有3个POST变量,但不再有POST正文。
I also tried stuff with jsonp and added orgins = * to the local.ini 我还尝试了jsonp的东西,并将orgins = *添加到local.ini
I'm not sure but I think you might be using the wrong syntax. 我不确定,但我认为您可能使用了错误的语法。 Instead of 代替
"contentType: 'application/json'," “ contentType:'application / json',”
try 尝试
"dataType: "json"," “ dataType:” json“,”
http://api.jquery.com/jquery.post/ http://api.jquery.com/jquery.post/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.