728x90
0
I am trying to return a json encoded string from PHP script.
$.post("order.php", { product: product_id, coupon: coupon },
function(data) {
$("#price").html("$" + data.price);
$("#discount").html("$" + data.discount);
$("#total").html("$" + data.total);
});
I tried to use alert function in callback to see returning value from PHP:
{"price":249,"discount":"0.00","total":249}
but value of #price and rest elements is "$undefined".
Please help.
add a comment
1
It seems you just have to parse the JSON data into an object using parseJSON()
:
$.post("order.php", { product: product_id, coupon: coupon },
function(data) {
data = $.parseJSON( data );
$("#price").html("$" + data.price);
$("#discount").html("$" + data.discount);
$("#total").html("$" + data.total);
});
'WEB > jQuery' 카테고리의 다른 글
jQuery API 정복 - 자식 요소들 찾기, children() (0) | 2018.05.21 |
---|---|
특정 div 프린트 하기 (0) | 2018.05.11 |
jQuery.getScript, JavaScript 파일을 로드하고 실행 (0) | 2018.04.19 |
Refresh Part of Page (div) (0) | 2018.04.13 |
jQuery Select Box Control (0) | 2018.04.13 |