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"