使用带有Phonegap(Cordova)的jQuery $ .post for Android(Using jQuery $.post with Phonegap (Cordova) for And

编程入门 行业动态 更新时间:2024-10-17 23:33:11
使用带有Phonegap(Cordova)的jQuery $ .post for Android(Using jQuery $.post with Phonegap (Cordova) for Android)

我有一个Phonegap应用程序,需要将数据发布到远程服务器。 但是,当我尝试使用jQuery的$ .post时,它永远不会进入回调。

这是我的Javascript:

$(document).ready(function() { $('form').submit(function() { console.log('about to post'); $.post('http://mysubdomain.mydomain.com/index.php', function(data) { console.log('In callback'); console.log(data); }); }); });

当我运行它并查看Eclipse LogCat时,我看到“即将发布”但我从未看到“在回调中”。 我将其转储到我服务器上的PHP文件中的脚本标签中,以确保它是正确的,当我刷新页面时,我看到HTML显示在Javascript控制台中。 我已经将res / xml中config.xml文件中的所有域列入白名单,所以我不明白为什么这不起作用。 如果有人有任何见解,请告诉我。 谢谢!

I have a Phonegap app that needs to post data to a remote server. However, when I try to use jQuery's $.post, it will never go into the callback.

Here is my Javascript:

$(document).ready(function() { $('form').submit(function() { console.log('about to post'); $.post('http://mysubdomain.mydomain.com/index.php', function(data) { console.log('In callback'); console.log(data); }); }); });

When I run this and look in the Eclipse LogCat, I see "about to post" but I never see "In callback". I dumped this into a script tag in my PHP file on my server to make sure it is correct and sure enough, when I refresh the page I see the HTML show up in the Javascript console. I already whitelisted all domains in my config.xml file in res/xml, so I don't understand why this is not working. If anyone has any insight please let me know. Thanks!

最满意答案

我猜你永远不会进入成功回调的原因是发生了某种错误。 尝试相同的请求,例如:

$(document).ready(function() { $('form').submit(function() { console.log('about to post'); $.ajax({ url: 'http://mysubdomain.mydomain.com/index.php', data: {}, // your data (if any) should go here dataType: 'application/json' // or whatever you expect back success: function(data) { console.log('In callback'); console.log(data); }, error: function(error) { console.log(error); } }); }); });

这至少应该告诉你错误......

I would guess the reason you are never entering the success callback is that some kind of error is happening. Try the same request with something like:

$(document).ready(function() { $('form').submit(function() { console.log('about to post'); $.ajax({ url: 'http://mysubdomain.mydomain.com/index.php', data: {}, // your data (if any) should go here dataType: 'application/json' // or whatever you expect back success: function(data) { console.log('In callback'); console.log(data); }, error: function(error) { console.log(error); } }); }); });

That should at least show you the error...

更多推荐

post,Javascript,电脑培训,计算机培训,IT培训"/> <meta name="description&q

本文发布于:2023-07-22 09:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cordova   Phonegap   jQuery   Android   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!