PhoneGap的Drupal JSON POST
我试图发送POST请求到Drupal的服务模块和JSON_Server模块,但是我越来越
{“#error”:true,“#data”:“无效的方法”}
由于PhoneGap在手机上从本地运行html文件,因此我需要担心JSONP。 我遇到的问题是我必须POST数据,并且JSONP只允许GET。 任何想法都会有所帮助。 谢谢!
//SEND REQUEST AND CALLBACK FUNCTION var req; DrupalService.prototype.request = function(dataObject, callback){ req = false; var url = DRUPAL_JSON_URL; var params = "data="+dataObject; try { req = new XMLHttpRequest(); } catch(e) { req = false; } if(req) { req.onreadystatechange = function() {//Call a function when the state changes. if(req.readyState == 4 && req.status == 200) { console.log(">> "+req.responseText); } } req.open("POST", url, false); req.send(params); } }
所以我想通了,它必须与冲突的内容类型
确保你将它设置为
Content-Type = application / x-www-form-urlencoded;
var DRUPAL_JSON_URL = "http://myDrupalsSite.com/services/json";
var req;
DrupalService.prototype.request = function(dataObject, callback){
var url = DRUPAL_JSON_URL;
req = false;
var params = "method=system.connect";
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
if(req) {
req.onreadystatechange = function() {//Call a function when the state changes.
if(req.readyState == 4 && req.status == 200) {
alert("test " + req.responseText)
console.log("RESPONSE "+req.responseText);
}
}
req.open("POST", url, true);
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
req.send(params);
}
}
链接地址: http://www.djcxy.com/p/22299.html
上一篇: Drupal JSON POST from PhoneGap
下一篇: How to display the Authentication Challenge in UIWebView?