如何将数据从phonegap发送到快速应用程序? [英] How do I send data from phonegap to an express app?

查看:121
本文介绍了如何将数据从phonegap发送到快速应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在phonegap内发出一个ajax post请求,然后在一个快速应用程序中接收数据。这是我的代码:

I'm trying to make an ajax post request inside of phonegap, and then receive that data inside of an express app. This is what my code looks like:

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');
        }
    });

Express:

    app.get('/test' , function (req , res){
  console.log(req.body);
  res.redirect('/');
    });

在我的快速控制台内部,我看到一个空对象。在phonegap控制台里面记录一个错误。

Inside of my express console I am seeing an empty object. Inside the phonegap console it is logging an error.

有人知道我在这里失踪吗?这是甚至正确的方向能够发送数据从phonegap到express?我想最终存储数据在一个mongodb一旦它打到快速应用程序。

Does anybody know what I'm missing here? Is this even the right direction for being able to send data from phonegap to express? I want to eventually store the data inside of a mongodb once it hits the express app.

请让我知道。感谢!

推荐答案

dataType:'jsonp'替换为 dataType:'json',您的ajax调用不会触发 jsonp

Replace dataType: 'jsonp' with dataType: 'json', your ajax call will not fire with jsonp

这篇关于如何将数据从phonegap发送到快速应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆