Ajax call to bounce block for PHP service
I have created a web service using php and when I access from the rest client I get the correct JSON response. I am calling a method from an AJAX call integrated into a Drupal site. the service response is HTML, so it will block the error.
PHP CODE:
$api_response = array('result' => 1, 'message' => 'Successfully user added!');
header("Content-Type: application/json; charset=utf-8");
$json_response = json_encode($api_response);
echo $json_response;
JS CODE:
$.ajax({
url:'http://localhost:8888/testService.php',
type: 'GET',
dataType:'json',
success: function(data) {
console.log("SUCCESS DATA");
},
error: function(error) {
alert("ERROR OCCURED 123");
}
});
+3
source to share