phonegap android ajax请求适用于GET但不适用于POST

发布于 2024-12-09 15:37:20 字数 1084 浏览 0 评论 0原文

在我的phonegapp-ed android应用程序中发送以下请求适用于GET,但不适用于POST。 有了 GET,一切就正常了。使用 POST,请求会通过,但 POST 变量 服务器端未通过,服务器返回 json 响应显示“未提供参数。”

POST 在我们的移动应用程序中工作正常 - 这只是我们遇到问题的phonegap 应用程序。我在这里缺少什么???预先感谢您提供的任何帮助!

我尝试过更改 $.ajax 调用、android 清单以及我能想到的所有设置。

另外,我正在使用 Android 2.2 和 Phonegap 1.0


function goTeam(){ 
    var dataString={lat:currentLocation.lat(),lng:currentLocation.lng()}; // this all works 
    $.ajax({ 
            url: 'http://example.com/request/goTeam', 
            data: dataString, 
            dataType: 'json', 
            success: 
                    function(b) { 
                            if(b.status==1){  // woo hoo! it works 
                            } else { 
                                    // the request went through but something was wrong - this is what i'm getting with POST 
                            } 
                    }, 
            type: 'post',  // works with GET, doesn't work with POST 
            error: function(jqXHR, textStatus, errorThrown){ alert("Noooo."); } 
    }); 

Sending the below request in my phonegapp-ed android app works for GET but not POST.
With GET, everything works. With POST, the request goes through but the POST variables
are not coming through on the server side, and the server returns a
json response that says 'no parameters supplied.'

POST works fine from our mobile app - it is just the phonegap app where we are having an issue. What am i missing here??? Thanks in advance for any help you can provide!

I've tried changing the settings on the $.ajax call, the android manifest, everything I can think of.

Also, i'm using Android 2.2 and Phonegap 1.0


function goTeam(){ 
    var dataString={lat:currentLocation.lat(),lng:currentLocation.lng()}; // this all works 
    $.ajax({ 
            url: 'http://example.com/request/goTeam', 
            data: dataString, 
            dataType: 'json', 
            success: 
                    function(b) { 
                            if(b.status==1){  // woo hoo! it works 
                            } else { 
                                    // the request went through but something was wrong - this is what i'm getting with POST 
                            } 
                    }, 
            type: 'post',  // works with GET, doesn't work with POST 
            error: function(jqXHR, textStatus, errorThrown){ alert("Noooo."); } 
    }); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

能怎样 2024-12-16 15:37:20

您是否尝试跨域请求?只有 GET 请求才以这种方式工作。您可以使用 JSONP 来进行此类请求,但只有 GET 有效。

Are you trying cross-domain requests? Only GET requests work this way. You can use JSONP for this kind of request, but only GET works.

高速公鹿 2024-12-16 15:37:20

Phonegap 确实适用于 GET 和 POST - 跨域安全问题不适用。我们的代码有一个特殊的错误,导致它无法工作。 Phonegap 太棒了!

Phonegap does work with both GET and POST - cross-domain security issues do not apply. We had an idiosyncratic error our code that was preventing it from working. Phonegap is pretty awesome!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文