In the javascript-ajax return value, some inexplicable blank lines will appear in the first place.

Source: Internet
Author: User
Tags php template
I am using wordpress. I don't know why some blank lines will appear in the returned results. Jquery {code...} PHP {code ...}

I am using wordpress. I don't know why some blank lines will appear in the returned results.

Jquery

$.ajax({        type:'post',        url:localcurrent.ajax_url,        data:favorite_data,        success:function(response){            alert(response);        }    });

PHP

Function favorite_post () {$ post_id = $ _ POST ["post_id"]; $ user_id = get_current_user_id (); $ favorite = favorite_get ($ post_id, 1 ); // determine whether the user has added this article to the favorites if (! In_array ($ user_id, $ favorite) {// This item is not added to the user's favorites. To add the favorites favorite_add ($ user_id, $ post_id); echo 'add'; exit ;} else {// The user has added this item to favorites. To remove the added item from favorites, favorite_del ($ user_id, $ post_id); echo 'delete'; exit;} echo 'error'; exit ;} add_action ('wp _ ajax_favorite_post', 'favorite _ Post ');

Reply content:

I am using wordpress. I don't know why some blank lines will appear in the returned results.

Jquery

$.ajax({        type:'post',        url:localcurrent.ajax_url,        data:favorite_data,        success:function(response){            alert(response);        }    });

PHP

Function favorite_post () {$ post_id = $ _ POST ["post_id"]; $ user_id = get_current_user_id (); $ favorite = favorite_get ($ post_id, 1 ); // determine whether the user has added this article to the favorites if (! In_array ($ user_id, $ favorite) {// This item is not added to the user's favorites. To add the favorites favorite_add ($ user_id, $ post_id); echo 'add'; exit ;} else {// The user has added this item to favorites. To remove the added item from favorites, favorite_del ($ user_id, $ post_id); echo 'delete'; exit;} echo 'error'; exit ;} add_action ('wp _ ajax_favorite_post', 'favorite _ Post ');

I think there are two situations:
1. Something in the PHP template as mentioned above.
2. The returned data contains UTF-8 text in BOM format.

Is the php tag deleted at the top of the php template file? I did the same before. After checking for a long time, I found that I deleted some things at the top of the template file.

Use a browser to capture packets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.