How to return PHP variables on success AJAX/jQuery POST

前端 未结 3 1258
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 00:39

How do I use AJAX to return a variable in PHP? I am currently using echo in my controller to display a price on dropdown .change in a div called pr

3条回答
  •  被撕碎了的回忆
    2020-12-15 01:06

    echo json_encode($RESPONDE);
    exit(); 
    

    The exit is not to display other things except answer. RESPONDE is good to be array or object. You can access it at

    success: function(data)
                 { data }
    

    data is the responde array or whatever you echo.. For example...

    echo json_encode(array('some_key'=>'yesss')); exit();
    

    at jquery

    success: function(data){ alert(data.some_key); }
    

提交回复
热议问题