The jquery Ajax program splits the string returned by the PHP program to always have a problem

Source: Internet
Author: User
jquery Ajax program is always a problem when slicing a string returned by a PHP program
For example, the PHP program outputs a

Echo ' yt| '. $row ["Dig"];

The AJAX program slices it:
function Dig (ID) {//when clicking on a vote link
var content = document.getElementById ("Dig" +id); Get the element that says "cast a vote"
Gets the element that displays the number of votes, whose id attribute value is a number, similar to id= "3"
var dig = document.getElementById (ID);
$.ajax ({
Type: "Get",
URL: "service.php",
Data: {id:id,n:math.random ()},//Send record ID to service.asp
Beforesend:function () {$ (DIG). HTML (");},
Success:function (data) {//process the returned
R=data.split ("|");
Alert (r[0]);
if (r[0] = = "YT") {//The case has already been cast
$ (content). HTML ("You've already voted!" ");
$ (DIG). HTML (r[1]); Show the original number of votes
}
else if (data = = "NoData")//no record found
{Alert ("Parameter Error! ");}
else{
$ (DIG). HTML (data); Server modification succeeded, number of votes updated
$ (content). HTML ("vote success");//will vote for a vote to succeed
SetTimeout ("Rightinfo (" +id+ ")", 3000);//3 seconds after call Rightinfo (ID)
}}}); }
It's always a shard.
After testing, the problem is that r[0] = = "YT" returns false. But with alert (r[0]), the output is YT, but there seems to be a blank line on the YT.
Before using ASP program output There is no such problem, previously:
Response.Write ("YT" & "," &rs ("Dig"))
This question can not be found on the internet, what is the reason AH

Share to:


------Solution--------------------
1. Verify that there are no blank lines in front of your PHP file
2. If your file is Utf-8 encoded, make sure no BOM header
------Solution--------------------
Reference:
For example, the PHP program outputs a

Echo ' YT
------Solution--------------------
'. $row ["Dig"];

The AJAX program slices it:
function Dig (ID) {//when clicking on a vote link
var content = document.getElementById ("Dig" +id); Get the element that says "cast a vote"
  • Related Article

    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.