Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Phonegap onclick不工作_Php_Android_Cordova - Fatal编程技术网

Php Phonegap onclick不工作

Php Phonegap onclick不工作,php,android,cordova,Php,Android,Cordova,我是phonegap的新手,我的按钮有一个大问题。当我在浏览器上执行时,它可以完美地工作并正确地插入我的数据库,但当我使用phonegap developer时,它不工作,什么也没有发生……有人能帮我吗 HTML代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="format-detection" content="telephone=n

我是phonegap的新手,我的按钮有一个大问题。当我在浏览器上执行时,它可以完美地工作并正确地插入我的数据库,但当我使用phonegap developer时,它不工作,什么也没有发生……有人能帮我吗

HTML代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <!--<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />-->
    <link rel="stylesheet" type="text/css" href="css/form_cadastrar.css" />
    <link rel="stylesheet" href="css/jquery.mobile-1.2.1.min.css" />
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/jquery.mobile-1.2.1.min.js"></script>

    <title>Cadastro</title>
</head>
<body>
     <form id="formCliente" >
        <div id="control">  
            <div class="control-group">
              <div class="cad-titulo">
                    <span>Posso te conhecer?</span>
                </div>
            </div>             
            <div class="control-group">
                <label class="control-label">
                    Nome
                </label>
                <div class="controls">
                    <input  type="text" autofocus name="nome" id="nome" class="campos" required="required">
                </div>
            </div>
             <div class="control-group">
                <label class="control-label">
                    Sobrenome
                </label>
                <div class="controls">
                    <input type="text" name="sobrenome" id="sobrenome" class="campos" required="required">
                </div>
            </div>
             <div class="control-group">
                <label class="control-label">
                    CPF
                </label>
                <div class="controls">
                    <input type="text" placeholder="888.888.888-88" name="cpf" id="cpf" class="campos" required="required">
                </div>
            </div>
             <div class="control-group">
                <label class="control-label">
                    Email
                </label>
                <div class="controls">
                    <input type="email" name="email" id="email" class="campos" required="required">
                </div>
            </div>
             <div class="control-group">
                <label class="control-label">
                    Crie&nbsp;uma&nbsp;senha
                </label>
                <div class="controls">
                    <input type="password" name="senha" id="senha1" class="campos">
                </div>
            </div>
             <div class="control-group">
                <label class="control-label">
                    Repita&nbsp;a&nbsp;senha
                </label>
                <div class="controls">
                    <input type="password" name="senha2" id="senha2" class="campos">
                </div>
            </div>
             <div class="control-group">
                <input onclick="enviar()" type="button"><span>ENVIAR</span></button>
                </div>

             <div class="control-group">
                <button onClick="history.go(-1)" type="button" class="btn btn-danger"><span>VOLTAR</span></button>
                </div>   
            </div>

         </div>   

        </form>  

    </body>

</html>    

      <script>
function enviar(){ 
var formula = $('#formCliente').serialize();

$.ajax({

    type:'POST',
    data: formula,
    url:'http://localhost/teste/www/cadastrar.php',
    success: function(data){

    if(data == '' || data == 0){
        alert('Occoreu um erro no Banco de Dados');
        window.location = "";
    }

    if(data == 1){
        alert('registro salvo com sucesso'); 
         window.location.href = "login.html";   
        }


    }


});

}

</script>

地籍
有空吗?
诺姆
Sobrenome
中央公积金
电子邮件
克里乌马森哈
塞尼亚雷皮塔酒店
羡慕
沃尔特
函数enviar(){
var formula=$('#formCliente').serialize();
$.ajax({
类型:'POST',
数据:公式,
网址:'http://localhost/teste/www/cadastrar.php',
成功:功能(数据){
如果(数据=''| |数据==0){
警报(“Occoreu um erro no Banco de Dados”);
window.location=“”;
}
如果(数据==1){
警报(“注册齐射成功”);
window.location.href=“login.html”;
}
}
});
}
PHP代码:

<?php
$hostname = 'localhost';
$username = 'root';
$password = 'pass';
$database = 'mydb';

try {
$pdo = new PDO("mysql:host=$hostname;dbname=$database", $username,    
$password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    //echo 'Conexao efetuada com sucesso!';
}
catch(PDOException $e)
{
    echo $e->getMessage();
}

 $sql = 'INSERT INTO usuario (nome, sobrenome, cpf, email, senha)' ;
 $sql .= 'VALUES (:nome, :sobrenome, :cpf, :email, :senha)';

try {

$recebeConexao = $pdo->prepare($sql);

$recebeConexao->bindParam(':nome', $_POST['nome'], PDO::PARAM_STR);
$recebeConexao->bindParam(':sobrenome', $_POST['sobrenome'],  
PDO::PARAM_STR);
$recebeConexao->bindParam(':cpf', $_POST['cpf'], PDO::PARAM_STR);
$recebeConexao->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$recebeConexao->bindParam(':senha', $_POST['senha'], PDO::PARAM_STR);

$recebeConexao->execute();

if($recebeConexao == true){
$cadastro = 1;
}else{
$cadastro = 0;
}


} catch (PDOException $ex) {
echo "Erro inserção";
}
echo (json_encode($cadastro));

?>

您可能会遇到一些问题。。。您的Ajax请求将发送到localhost,设备上的localhost将是设备本身。您需要将其替换为运行PHP的机器的IP地址或主机名,并确保手机可以看到该机器(通常是通过将它们都放在同一无线网络上)

此外,如果您使用Cordova 5 for Android和/或iOS,您可能还需要添加适当的内容安全策略元标记,以允许向服务器发送Ajax请求。例如,在Cordova应用程序的index.html标题中添加如下内容:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://YOUR_SERVER_HOSTNAME_OR_IP_ADDRESS">

对于在iOS 9上运行,如果您的服务器未使用SSL进行保护,您还需要为iOS 9引入的应用程序传输安全(ATS)配置一个适当的例外。要做到这一点,您需要修改项目的plist,其中包含要允许非SSL连接的服务器列表。因此,您可以在iOS项目的.plist中添加类似的内容:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
      <key>yourservergoeshere.com</key>
      <dict>
        <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
        <true/>
    </dict>
  </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
YourServerGoesher.com
NSTemporary ExceptionalLowsInSecureHttpLoads

对这两个问题的适当讨论是。

这里可能有两个问题。。。您的Ajax请求将发送到localhost,设备上的localhost将是设备本身。您需要将其替换为运行PHP的机器的IP地址或主机名,并确保手机可以看到该机器(通常是通过将它们都放在同一无线网络上)

此外,如果您使用Cordova 5 for Android和/或iOS,您可能还需要添加适当的内容安全策略元标记,以允许向服务器发送Ajax请求。例如,在Cordova应用程序的index.html标题中添加如下内容:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://YOUR_SERVER_HOSTNAME_OR_IP_ADDRESS">

对于在iOS 9上运行,如果您的服务器未使用SSL进行保护,您还需要为iOS 9引入的应用程序传输安全(ATS)配置一个适当的例外。要做到这一点,您需要修改项目的plist,其中包含要允许非SSL连接的服务器列表。因此,您可以在iOS项目的.plist中添加类似的内容:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
      <key>yourservergoeshere.com</key>
      <dict>
        <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
        <true/>
    </dict>
  </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
YourServerGoesher.com
NSTemporary ExceptionalLowsInSecureHttpLoads

对这两个问题的适当讨论是。

这里可能有两个问题。。。您的Ajax请求将发送到localhost,设备上的localhost将是设备本身。您需要将其替换为运行PHP的机器的IP地址或主机名,并确保手机可以看到该机器(通常是通过将它们都放在同一无线网络上)

此外,如果您使用Cordova 5 for Android和/或iOS,您可能还需要添加适当的内容安全策略元标记,以允许向服务器发送Ajax请求。例如,在Cordova应用程序的index.html标题中添加如下内容:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src http://YOUR_SERVER_HOSTNAME_OR_IP_ADDRESS">

对于在iOS 9上运行,如果您的服务器未使用SSL进行保护,您还需要为iOS 9引入的应用程序传输安全(ATS)配置一个适当的例外。要做到这一点,您需要修改项目的plist,其中包含要允许非SSL连接的服务器列表。因此,您可以在iOS项目的.plist中添加类似的内容:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
      <key>yourservergoeshere.com</key>
      <dict>
        <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
        <true/>
    </dict>
  </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
YourServerGoesher.com
NSTemporary ExceptionalLowsInSecureHttpLoads

对这两个问题的适当讨论是。

这里可能有两个问题。。。您的Ajax请求将发送到localhost,设备上的localhost将是设备本身。您需要将其替换为运行PHP的机器的IP地址或主机名,并确保手机可以看到该机器(通常是通过将它们放在同一根电线上)