2014-04-15 48 views
2

我正在尝试在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中,一旦它打到快速应用程序。

请让我知道。谢谢!

+0

已添加的访问= *权限火? – renanlf

+2

'localhost'不是移动设备的有效域,请使用IP地址 –

+0

@Renalf:我不确定你的意思。我在哪里包括这个?道森:这是否意味着我需要在收到数据之前托管我的快速应用程序? PhoneGap应用程序(波纹)和快速应用程序(本地主机)都在我的机器上运行。 – user3294779

回答

0

更换dataType: 'jsonp'dataType: 'json',你的Ajax调用不会jsonp

+0

这不是一个修复。此外,从我读过的stackoverflow jsonp是跨域请求所必需的。 – user3294779

相关问题