php - jQuery 以 json 格式从 php 返回结果

标签 php javascript jquery

我有一个 $.post 如何从 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 上放什么才能得到结果?

最佳答案

$.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
    });

关于php - jQuery 以 json 格式从 php 返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14208949/

相关文章:

javascript - 处理对动态生成的按钮的点击

Jquery 菜单 - 改变滑动功能

php - 无法连接到 imap Gmail/php imap

php - 当主键数据不连续时选择随机行

javascript - 如何在 Javascript 中返回计算的字符串表示形式

javascript - 实现 UI Router Hierarchy/category/category/product 的最佳方式

javascript - 选中复选框时删除按钮可见

javascript - 根据当前屏幕窗口大小为我的模态窗口设置最大高度

php - laravel POST 输入不起作用

php - 如何在 ci4 路由中传递任意数量的参数?