我正在尝试在phonegap中创建一个ajax post请求,然后在express app中接收这些数据。这是我的代码如下所示:如何将数据从phonegap发送到快速应用程序?
的PhoneGap:
$.ajax({
type: 'POST',
url:"http://localhost:3000/test",
data: {'test':'test'},
dataType: 'jsonp',
crossDomain: true,
success: function(data){
console.log('data successfully sent');
},
error: function(){
console.log('there was an error');
}
});
快递:
app.get('/test' , function (req , res){
console.log(req.body);
res.redirect('/');
});
在我的快递控制台我看到一个空的对象。在phonegap控制台内,它正在记录一个错误。
有人知道我在这里失踪了吗?这是否能够从phonegap发送数据表达的正确方向?我想最终将数据存储在一个mongodb中,一旦它打到快速应用程序。
请让我知道。谢谢!
已添加的访问= *权限火? – renanlf
'localhost'不是移动设备的有效域,请使用IP地址 –
@Renalf:我不确定你的意思。我在哪里包括这个?道森:这是否意味着我需要在收到数据之前托管我的快速应用程序? PhoneGap应用程序(波纹)和快速应用程序(本地主机)都在我的机器上运行。 – user3294779