I need some help with a JSON object and the Ajax call using it. I need to pass this data to update my database for some purpose:
JSON string:
[{"id":"1"},{"id":"10"},{"id":"2"},{"id":"3"},{"id":"4"},{"id":"5"},{"id":"6"},{"id":"7"},{"id":"8"},{"id":"9"}]
I am using AJAX Post. My code:
$.ajax({
url: "hello_world.php",
type: "POST",
data: JSON.stringify(jsonString),
processData: false,
contentType: 'application/json',
dataType: 'json',
success: function(data){
alert("Call success");
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error: " + xhr.status + "
" +
"Message: " + xhr.statusText + "
" +
"Response: " + xhr.responseText + "
" + thrownError);
}
});
PHP Code :
<?php
if(isset($_POST))
{
$json = file_get_contents('php://input');
$decoded = json_decode($json, TRUE);
echo $decoded;
}
?>