My task is simple that I am sending string to the server using jQuery AJAX inside a FirefoxOS App. The data is received but still it doesn't proceed to the success function and falls to the error function.
Following is the segment from manifest:
"permissions": {
"systemXHR": {
"description": "Required to make Ajax Calls over the Network"
}
},
"type": "privileged"
My Ajax function:
$('#btn_save_server').click(function() {
contacts = 'a line of text';
$.ajax({
type: "POST",
url: 'http://localhost/save_contacts.php',
xhrFields: { mozSystem: true },
data: { contacts: contacts },
beforeSend: function() {
console.log( contacts );
},
success: function(data) {
alert('done');
},
error: function(request, status, error) {
alert('error');
console.log( request );
console.log( status );
console.log( error );
}
});
});
And my server:
<?php
$contacts = $_POST['contacts'];
$contacts = json_encode( $contacts );
file_put_contents( 'contacts.txt', $contacts );
echo 'Finished';