Unwanted new line returned after AJAX request

☆樱花仙子☆ 提交于 2019-12-01 07:35:36
  1. Make sure there is nothing, preceeding the opening <?php in your classQuote.php
  2. Make sure there are no trailing characters / lines after the closing ?>
  3. Check to see if a ?> tag exists somewhere in the lines of code (follow flow from your __construct and where you invoke stuff)

Infact, it could prove helpful to leave out the closing tag. Another possibility is this:

  // capture output
            ob_start(); 
            require_once($ABS_APPS."/quotes/classQuote.php");
            $quote = new Quote();
            $quoteData = $quote->get($_POST["entryId"]);
            // If user comments his own entry we don't have to send the notification
            if($quoteData["UserAuthor"] != $_SESSION["User"]){
                $notification->newComment($_POST["username"], $quoteData["UserAuthor"], $_POST["entryId"], $_POST["app"]);
  // trim whitespace
            echo trim(ob_get_clean()); 
            }

If you're using jQuery

you can use jQuery.trim(responseData) in your AJAX success callback, to get rid of the white spaces

see also here http://api.jquery.com/jQuery.trim/

hope it helps

I fixed by these

  1. Make sure there is nothing, preceeding the opening
  2. Make sure there are no trailing characters / lines after the closing ?>
  3. Check to see if a ?> tag exists somewhere in the lines of code (follow flow from your __construct and where you invoke stuff)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!