I have accumulated and chopped up about 5 or 6 different tutorials of this now, and I still can't find out what's wrong!
Using JQuery Mobile (phonegap) to send and receive data to a PHP server. I cannot seem to get the JQuery script to pick up a response. PHP on server:
<?php
// Set up associative array
$data = array('success'=> true,'message'=>'Success message: worked!');
// JSON encode and send back to the server
echo json_encode($data);
?>
JQuery Function (Which is being called):
<script type="text/javascript">
$(function () {
$('#inp').keyup(function () {
var postData = $('#inp').val();
$.ajax({
type: "POST",
dataType: "json",
data: postData,
beforeSend: function (x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
}
},
url: 'removedmyurlfromhere',
success: function (data) {
// 'data' is a JSON object which we can access directly.
// Evaluate the data.success member and do something appropriate...
if (data.success == true) {
alert('result');
$('.results').html(data.message);
} else {
$('.results').html(data.message);
}
}
});
});
});
</script>
Sorry for the formatting, it all went pair shaped copying it across. Removed my url.
I know that the function is firing, because if I remove the alert('here'); and put it above the ajax call it displays.
Anybody know why the success function isn't calling? nothing shows in the div with class results on any browser.
Thanks!