小编Sim*_*n M的帖子

无法获得jQuery post请求在phonegap中工作

我正在尝试使用jQuery和Ajax将一些formdata发送到phonegap中的远程服务器.我在下面粘贴的代码在我的本地机器上的firefox中运行良好,但是当我在手机上启动它时它不起作用(android).我是否需要修改或添加一些内容到jquery代码以使其在phonegap中工作?

我在android清单中添加了INTERNET权限.

<!DOCTYPE HTML>
<html>
    <head>
        <title>Phonegap ajax test</title>

        <meta name="viewport" content="width=240, height=320, user-scalable=yes, initial-scale=2.5, maximum-scale=5.0, minimum-scale=1.0" />
        <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
        <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.0rc2.js"></script>

        <link rel="stylesheet" type="text/css" href="css/layout.css" />
        <link rel="stylesheet" type="text/css" href="js/jquery.mobile-1.0rc2.css" />

        <script type="text/javascript">    
            $(document).ready(function() {
                $('#infoForm').submit(function() {
                    var postTo = 'http://www.mysite.com/process.php';

                    $.post(postTo,$('#infoForm').serialize(), function(data) {
                        alert(data);       
                    });
                    return false;
                }); 

            });
        </script>
    </head>

    <body>      
        <div data-role="content">   
            <form method="post" id="infoForm">
                <input type="text" name="first_name" id="first_name" value="" placeholder="First Name"  />
                <input type="text" name="last_name" id="last_name" value="" …
Run Code Online (Sandbox Code Playgroud)

jquery cordova

4
推荐指数
1
解决办法
5527
查看次数

标签 统计

cordova ×1

jquery ×1