weixin_33726313 2015-02-10 14:30 采纳率: 0%
浏览 48

Phonegap Ajax发布错误

I have been searching high and low to come up with a solution to an error I am getting with a phonegap app I am building.

HTML

<form method="post" id="app-send" name="app-send">
        <input id="a" name="a" type="text">
        <input id="b" name="b" type="text">
        <input id="c" name="c" type="text">
        <input id="timestamp" name="timestamp" type="text">
        <input id="submit" name="submit" type="submit">
    </form>

JS

<script type="text/javascript">
        $(document).ready(function () {
            $('#app-send').submit(function (e) {
                var postData = $(this).serialize();
                $.ajax({
                    type: 'POST',
                    url: 'http://example.com',
                    dataType: 'json',
                    data: postData,
                    success: function (data) {
                        alert(data);
                    },
                    error: function () {
                        alert('error!');
                    }
                });

                return false;
            });
        });
    </script>

My Issue:

Everytime I test on phonegap developer app in the console I get back

"Proxy error for url: http://example.com undefined"
"HPE_INVALID_CONTACT http://example.com"

UPDATE

I have just tried this:

<form action="http://www.example.com" method="post" id="app-send" name="app-send">
    <input id="a" name="a" type="text">
    <input id="b" name="b" type="text">
    <input id="c" name="c" type="text">
    <input id="timestamp" name="timestamp" type="text">
    <input id="submit" name="submit" type="submit">
</form>

And this works. So how could I submit the data using AJax and stop the page from changing?

  • 写回答

3条回答 默认 最新

  • 7*4 2015-03-18 05:06
    关注

    I believe you are using phonegap injunction of jquery mobile

    You should add data-ajax="false" to your form element to stop the jquery mobile default behaviors.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题