2013-01-08 2 views
2

나는 $.post을 가지고 있습니다. 어떻게 결과를 PHP에서 다시 얻을 수 있습니까?jQuery는 json 형식의 PHP에서 결과를 다시 얻습니다.

$.post("sql/customer_save.php",{ what: "edit",customer_no: $customer_no}); 

PHP는 응답은 다시

echo json_encode(array("customer_id"=>$customer_id,"customer_no"=>$customer_no)); 

내가 다시 결과를 얻기 위해 $ .post에 넣어해야하는지?

답변

4
$.post("sql/customer_save.php",{ what: "edit",customer_no: $customer_no},function(resp) 
{ 
    //resp is your response 
    //You can try 
    console.log(resp); 
    console.log(resp["customer_id"]); //get the value of customer_id 
    console.log(resp["customer_no"]); //get the value of customer_no 
},"json"); 

또는

또한

$.post("sql/customer_save.php",{ what: "edit",customer_no: $customer_no},function(resp) 
    { 
     //resp is your response 
     //You can try 
     var data = $.parseJSON(resp); 
     console.log(data); 
     console.log(data["customer_id"]); //get the value of customer_id 
     console.log(data["customer_no"]); //get the value of customer_no 
    }); 
+0

Amirali을 사용할 수 있습니다 : 당신이 다른 무엇인지 궁금 가정 ...' "JSON"'매개 변수는'$의 .post에서 추가되었다 '전화. jQuery는 JSON 형식의 응답을 기대한다. – Wireblue

+0

각 필드를 따로 얻을 수있는 방법이 있습니까? customer_id, customer_no처럼 ?? –

+0

이런 식으로 resp.customer_id 및 resp.customer_no에 액세스하십시오. – Floricel

관련 문제