jQuery Ajax returns the whole page

前端 未结 6 1881
执念已碎
执念已碎 2020-11-28 10:52

I have a jquery-ajax function that sends data to a php script and the problem is with the return value, it returns the whole page instead of single value.

Thank you

6条回答
  •  一整个雨季
    2020-11-28 11:35

    So when you have this on your index.php at the beginning?:

    
    

    If this script is outputting further text then of course this will also be recieved by the Ajax call. You can put exit() after the echo to prevent the script from being processed further:

    if (isset($_POST["testAjax"])) { 
        echo $_POST["testAjax"];
        exit();
    }
    

    Also use dataType: 'text' as the value you return is obviously not HTML.


    Or as others suggest, create a new page that is responsible for dealing with the Ajax request. If you are doing more than just outputting the received value (i.e. more complex operations) you should do this anyway.

提交回复
热议问题