2017-02-24 36 views
1

時候才能json_encode值我已經成功地執行.post的$ Ajax調用,但能不能在那裏$updateUserResult是一些具體的操作後,獲取數據,

if ($updateUserResult) { 
     $response ['userId'] = $userId; 
    } 

    json_encode ($response); 

布爾值。在我的js文件上

submitHandler: function (form) { 
    var data = $(form).serialize(); 
    $.post("test.php", data).done(function(response) { 
     console.log(response); 
     }); 
    return false; 
} 

控制檯日誌顯示爲空。我錯過了什麼或流量是錯誤的.. ??

回答

1

你必須呼應輸出:

echo json_encode($response); 
1

要送你需要呼應它的輸出:

echo json_encode($response); 

並解析它成功回調。

var data=JSON.parse(response); 

console.log(data.userId);//will log userid 
+0

太感謝你了,由我愚蠢的問題:(.. –

+0

@RajeshDey不客氣。 –

0

你應該使用echo語句:

echo json_encode($response); 
0
please check 

$阿賈克斯({

type: "POST", 
url: "API_URL", 
data: {consultantId: consultantId 
}, 
success: function(data){ 
    console.log(JSON.stringify(data));  
} 
});