AJAX showing retrieved values as undefined

前端 未结 5 1857
暗喜
暗喜 2021-01-21 00:17

I am using AJAX to send values to PHP and retrieve the values from PHP. The problem is the value i am getting from PHP is viewed as undefined in AJAX. Please help me solve this

5条回答
  •  误落风尘
    2021-01-21 00:36

    Please try this. 1. Use output buffering so that only json data will recieve in ajax response 2. Provide json datatype in ajax

    
    

    Php Code

       //empty the current contents of the output buffer
        ob_end_clean();
    
        // Turns on output buffering
        ob_start();
    
        // print output
        echo json_encode(array("a" => "success", "b" => "timeout", "c" => "fail"));
    
        // Turn off buffering and print the contents
        ob_end_flush(); // Turn off buffering and print the contents
        exit;
    

提交回复
热议问题