drgzmmy6379 2012-04-11 00:55
浏览 13
已采纳

如何将PHP *变量*发送回jQuery而不回显?

I am using the ajax() function to send a string to a PHP file.

In case of a success, the PHP file echoes "the validation of the string was successful". But I would also like to send the actual string back to jQuery and put it in a div.

How can send back that string, without having to echo it along with the confirmation message?

Or should I put both messages into a string, send it to jQuery and have jQuery split that string? What's the best way?

  • 写回答

2条回答 默认 最新

  • dongtang1944 2012-04-11 01:03
    关注

    Putting what others have said into code, you might set up your PHP script to return a JSON-encoded object like so:

    $result = array(
      'message' => 'the validation of the string was successful',
      'original' => 'string sent by client'
    );
    
    echo json_encode($result);
    

    On the client side, you can then access each piece from your callback function like so:

    function (result) { 
      alert(result.message);
      // do something with result.original
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?