dszdiavv474681
dszdiavv474681
2016-12-01 09:14

json stringify需要使用javascript将它们放在变量中的2个数组

  • json
  • php
  • ajax
  • javascript
  • jquery

I have an ajax response in json format. Then in my javascript (ajax response success) i have the two arrays stringify. Now I need to place data in one curly bracket to 2 variables and then other curly bracket in another 2 variables.

Here's the code

var results = JSON.stringify(result).substr(1,JSON.stringify(result).length-2);

Here's the ajax(.js file)(part of it now whole code)

$.ajax({
  url: "ajax/default_q.php",
  dataType: "json", 
  type: 'POST',
  data: {dtime: n},

  success: function(result) {
    var results = JSON.parse(result);
    var mtime = results.microtime;
    var srp = results.srp;

    alert(mtime);
    alert(srp);

Here's the php

$sql = "SELECT microtime,srp FROM loading WHERE submit_id = 'XXXXXXXXXXXXXXXXXX' AND microtime BETWEEN UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 day)) and 1480573758";
$res   = mysqli_query($GLOBALS['link'],$sql);
while($row = mysqli_fetch_assoc($res)){
    $content[] = $row;
}
echo json_encode($content);

enter image description here

Ok. I want the microtime which is highligthed in yellow be stored in variable a so if I alert the a it will look like the photo below although not exactly the same. And same as the srp.

enter image description here

How will I achieve that. PLease help/.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答