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
Raghav
source
to share
1 answer
(Posted on behalf of the OP).
The PHP file was present in the same location as in the Drupal instance. The Drupal site has a page with a name service, so it returns an HTML template. I moved the service file outside of the Drupal instance and it worked.
0
halfer
source
to share