Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <form id="formUsuario">
- <input id="nomeUsuario" type="text" placeholder="Nome"></input> <br>
- <input id="sobrenomeUsuario" type="text" placeholder="Sobrenome"></input> <br>
- <input id="idadeUsuario" type="text" placeholder="Idade"></input> <br>
- <button id="enviar" type="submit" onclick="salvar()">Enviar</button>
- </form>
- <script type="text/javascript" src="cordova.js"></script>
- <script type="text/javascript" src="js/index.js"></script>
- <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
- <script type="text/javascript">
- function salvar(){
- var formula = $('#formUsuario').serialize();
- $.ajax({
- type: 'POST',
- dados: 'formula',
- url: 'http://localhost/projetos/wstest/cadastrar.php',
- success: function(data){
- if (data == 0) {
- alert('Erro ao se comunicar com o banco de dados!');
- window.location = "";
- }
- else if (data == 1) {
- alert('Registro salvo com sucesso!');
- }
- else{
- alert('Algo de errado aconteceu!');
- }
- }
- });
- }
- </script>
- </body>
- var app = {
- // Application Constructor
- initialize: function() {
- this.bindEvents();
- },
- // Bind Event Listeners
- //
- // Bind any events that are required on startup. Common events are:
- // 'load', 'deviceready', 'offline', and 'online'.
- bindEvents: function() {
- document.addEventListener('deviceready', this.onDeviceReady, false);
- },
- // deviceready Event Handler
- //
- // The scope of 'this' is the event. In order to call the 'receivedEvent'
- // function, we must explicitly call 'app.receivedEvent(...);'
- onDeviceReady: function() {
- app.receivedEvent('deviceready');
- },
- // Update DOM on a Received Event
- receivedEvent: function(id) {
- var parentElement = document.getElementById(id);
- var listeningElement = parentElement.querySelector('.listening');
- var receivedElement = parentElement.querySelector('.received');
- listeningElement.setAttribute('style', 'display:none;');
- receivedElement.setAttribute('style', 'display:block;');
- console.log('Received Event: ' + id);
- }
- <?php
- //Conecta ao banco de dados usando MySQLi
- function conectar()
- {
- try
- {
- //Localhost
- $host = "localhost";
- $user = "root";
- $password = "";
- $database = "webservice";
- $conn = mysqli_connect($host, $user, $password, $database);
- } catch (Exception $ex) {
- die("Erro de conexão: " . mysqli_connect_error());
- }
- return $conn;
- }
- <?php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement