responseText contains extra whitespace characters (new lines, line feeds), how to prevent and remove them?

前端 未结 6 529
忘了有多久
忘了有多久 2021-01-03 13:17

I have an ajax script that calls a php file.

The php file echos \"yes\" or \"no\", I want to use the strings to do logical comparisons.

In the javascript,

6条回答
  •  鱼传尺愫
    2021-01-03 13:36

    In my case I solved this problem by removing spaces between two php blocks in same php file ( "...? > < ?php..." ) which it requires by require_once() method.

    
    *this space might appear in the XHTTP responce*
    
    

    --OR-- you can send your data as JSON Object from the server script (php) , for this you can use json_encode() . for the client side (javascript) you may use eval(this.responce) .

提交回复
热议问题