Cordova jquery вставить в mysql - PullRequest
       18

Cordova jquery вставить в mysql

0 голосов
/ 21 февраля 2020

Во-первых, я очень новичок в разработке Cordova и мобильных приложений, поэтому я не уверен, есть ли какие-то зависимости / плагины, которые мне не хватает. Я слежу за уроками, но мало информации обо всех нужных мопсах и т. Д. c. Я просто проверяю связь с моей удаленной базой данных mysql, используя android studio emulator со следующим сценарием.

При запуске моего приложения я просто получаю предупреждение об ошибке "Произошла ошибка", сообщающая мне код не ломается, но не вставляет мои данные.

Я также считаю, что мой конфиг. xml разрешает подключения ко всем адресам.

Я также проверил его в браузере с фиксированными значениями, чтобы убедиться, что с моим php кодом нет проблем.

Я чувствую, что мое приложение не подключается / не взаимодействует с моим удаленным URL.

Спасибо за помощь

index. html Cordova local

<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <meta http-equiv="Content-Security-Policy" content="default-src &apos;self&apos; data: gap: https://ssl.gstatic.com &apos;unsafe-eval&apos;; style-src &apos;self&apos; &apos;unsafe-inline&apos;; media-src *; img-src &apos;self&apos; data: content:;">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <link rel="stylesheet" type="text/css" href="js/jquery-1.5.0.mobile.min.css">
        <style>
        /* For avoiding title truncation in wp8 */
        .ui-header .ui-title {
                overflow: visible !important;
        }
        /* For fixing the absolute position issue for the default cordova gen page*/
        #cjp-accordion1 .app {
                left: 5px !important;
                margin: 5px !important;
                position: relative !important;
        }
        </style>
        <title>Hello World</title>
    </head>
    <body>
    <input type="text" placeholder="write your first name" id="firstname">
    <input type="text" placeholder="write your last name" id="lastname">
    <button id="sub">Submit result</button>
<script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/jquery-1.11.1.min.js" id="cordova-jquery"></script>
        <script type="text/javascript" src="js/jquery-1.5.0.mobile.min.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="js/insert.js"></script>
    </body>
</html>

insert. js Cordova local

$("#sub").on("click", function(){
var firstname=$("#firstname").val();
var lastname=$("#lastname").val();
var dataString="firstname="+firstname+"&lastname="+lastname;
alert(dataString);
                if($.trim(firstname).length >0 & $.trim(lastname).length >0) {
                    $.ajax({
                        type:"POST",  //Request type
                        data:{firstname:firstname, lastname:lastname},
                        url: "http://www.urlToRemoteServer.co.za/insert.php",
                        cache:false,
                        success:function(data) {
                            console.log(data);
                            alert('Con Success');
                        },
                        error:function(data)
                        {
                            console.log(data);
                            alert('There was an error');
                        }
                    })
                }
                else {
                    alert('Input fields are empty');
                }
});

insert. php на моем удаленном веб-сервере

<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

$config = parse_ini_file('config/config.ini'); 
$mysqli = mysqli_connect($config['server'],$config['username'],$config['password'],$config['dbname'],3306);
if($firstname){
 $sql = "INSERT INTO `cordova_test` (`firstname`, `lastname`) VALUES ('$firstname','$lastname')";
 $result = $mysqli->query($sql);
    if($result) {
        echo $firstname." ".$lastname;
    } 
    else {
        echo "unable to insert data";
    }
}
else{
echo "No Data"; 
}
?>

config . xml Кордова местная

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.psimation.jquery" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>jquery</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>
...