James
James

Reputation: 1706

Getting array data from PHP to jQuery for outputting

Here is the partial code from the remove PHP file:

if($action == 'trackings_get') {
    $result = $trackings->get(getCourierSlugByID($GLOBALS['tracking_id']), $GLOBALS['tracking_id']);
    $result_history = $result['data']['tracking']['checkpoints'];

    echo json_encode($result_history);

    // debugging
    //pretty_print($result_history);
}

Here is the JS from the remote site i am trying to call the data for:

$.ajax({
  url: '/login/tracking.php',
  type: 'POST', 
  dataType: "json",
  data: {
    action: action,
    tracking_id: tracking_id
  }, 
  success: function(json){ 
    //debug
    alert(JSON.stringify(json));
  }
});

Upvotes: 0

Views: 57

Answers (2)

ali zarei
ali zarei

Reputation: 1241

i try this code in inspect element in this page https://tracking.ambientlounge.com/

function test(){
$.ajax({
  url: 'your url',
  type: 'POST', 
  dataType: "json",
  data: {
    action: "action",
    tracking_id: "tracking_id"
  }, 
  success: function(json){ 
    //debug
    console.log(json);
  }
});


}

result is array . dont need JSON.stringify .

Upvotes: 1

ali 20 developer
ali 20 developer

Reputation: 21

try this

function test(){
$.ajax({
  url: 'url',
  type: 'POST', 
  dataType: "json",
  data: {
    action: action,
    tracking_id: tracking_id
  }, 
  success: function(json){ 
  }
});


}

Upvotes: 1

Related Questions