我正在开始使用cordova / phonegap应用程序。
我希望所有数据库连接与服务器同步(我在本地运行SQLite数据库,并希望与服务器中的SQL同步)。要尝试同步,我有以下代码:
function post(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
好的,但由于我是AJAX的新手,我做错了什么。我想要的是显示交易的结果,但它会将我重定向到另一个显示结果的页面。
我该怎么做?
修改
我换成了AJAX,这是我的新功能:
var formData = {name:"ravi",age:"31"}; //Array
$.ajax({
url : "http://........",
type: "POST",
data : formData,
success: function(data, textStatus, jqXHR)
{
console.log("Data:");
console.log(data);
console.log("textStatus:");
console.log(textStatus);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert("Something went wrong");
}
});
但是我收到了这个错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.