Ciao a tutti e grazie in anticipo. Sto usando Phonegap 2.1.0. In whitelist tutto è accettato ..Post Ajax non funzionante - Jquery Phonegap Android
**<access uri="*" subdomains="true" />
<access origin=".*" subdomains="true"/>**
sto usando questa funzione per richiamare un file php remota dal mio server web dell'università:
var postData = $(this).serialize();
$.ajax({
type: 'POST',
url: 'http://--/smartphone/login.php',
dataType : 'json',
data: postData,
success: function(data){
alert("good");
},
error: function(){
alert('problem!');
}
});
IL file php è solo per motivi di debug in questo modo:
<?php
header('Content-Type: application/json');
$sample = array(
'name'=>'My Name',
'email'=>'[email protected]'
);
echo json_encode($sample);
?>
Ma ajax richiesta non sta accadendo .. in Eclipse I Continuo a ricevere questo errore quando clicco presento:
JSCallback Error: Request failed with status 0 at file:///android_asset/www/js/cordova-2.1.0.js:3743
Inoltre, ho dimenticato di aggiungere, è che posso aprire l'url come collegamento dall'emulatore. Funziona bene.
* codice html : *
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Smart Greenhouse</title>
</head>
<body>
<div id="container">
<img src="css/images/smart_green_house.png" class="logo" alt="l1ogo" />
<form id="login_form" class="first_display" >
<label class="title"> E-mail:</label>
<input id="1" type="email" class="input" size="45" name="email" />
<label class="title"> password:</label>
<input id="2" type="password" class="input" size="45" name="password" />
<input id="3" class="submit_type" type="submit" value="login" />
</form>
</div>
</body>
</html>
ho cercato penso praticamente l'intero web ... 2 giorni Ricerca ... tutto è stato testato .. Grazie mille.
'' http: // -/smartphone/login.php' è un URL valido? Non mi sembra. –
- sta per il dominio ... come mydomain.example.com .. Mi scuso se questo è frainteso .. – gnnpls
Prova ad aggiungere "Access-Control-Allow-Origin: *" HTTP-header sul lato PHP, controlla se funziona. – onon15