AnsweredAssumed Answered

AJAX Returns Incorrect data

Question asked by Haroon Khaleeq on Oct 24, 2014
Latest reply on Oct 27, 2014 by Haroon Khaleeq
This conversation has been merged. Please reference the main conversation:

I made an ajax call to retrieve some data. The response is JSON encoded data but it doesn't return JSON response instead it gives me this: Sometimes it works fine some times it does not.....

"<script>            if (parent.location == window.location) {
                window.location = "http:\/\/localhost\/imerge\/#Leads";
            } else {

Well, sometimes it works when i reload the page or when i repair and rebuild the same code.
The ajax call and php code is given below for your better understanding:

        url: "index.php?module=Leads&action=getPhonePT&sugar_body_only=true",
        type: "GET",
  dataType: "JSON",   
        data: "id=",
   success: function(data)
   error: function(msg)
    alert("Problem in Data Accessing. Try Reloading the Page.");
    //it comes here....!!!


 header('Content-Type: application/json');  //print_r($_REQUEST);
  $lead_id = $_REQUEST['id'];
  //echo $lead_id;

  $tableName = "phone_pt";
  $relatedPhone = array();
$result = $GLOBALS['db']->query("SELECT * FROM $tableName where parent_id='$lead_id'");
if($result->num_rows > 0){
  while($row = $GLOBALS['db']->fetchByAssoc($result)){
   $relatedPhone[] = $row;
  //echo "Hello123";
  // $GLOBALS['log']->fatal(print_r($relatedPhone,true));
  echo json_encode($relatedPhone);