samedi 9 mai 2015

Ajax call taking to failure block for php service

I have created a web service using php and when I access from a rest client I get the proper JSON response. I am calling the method from ajax call integrated in a drupal site. the service response is HTML hence it is going to error block.

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");
        }
      });

Help appreciated

Aucun commentaire:

Enregistrer un commentaire