$.get("/student/Studentnumber.php", $("myform").serialize(),
function(data){
alert(data);
if(data.substring(0,7) == 'STDERR'){
//$("#MYSPAN").text(data.substring(8));
} else {
//$("#MYSPAN").text(data);
}
}
);
In the Above Script I have The PHP response coming from the “Studentnumber.php” .The “Data” field contains the Contains the “Student NAME” if the correct number is entered .if a wrong number is entered it displays the “STDERR:SNO NOT VALID “.Now Here I want the respone only “SNO not VALID ” when a wrong number is entered .I want to over come the “STDERR:”
You’re close.
The index of the
.substring()calls is off by 1.Try it out: http://jsfiddle.net/2GcS3/
Update: This answer will still work, if you use
$.trim()to get rid of the extra white space.Otherwise, use the answer below.
EDIT: From your comment, there is a space at the beginning of the STDERR. In that case, you need to go back to the numbers you had, and add that space to the
STDERRstring for comparison.Try it out: http://jsfiddle.net/2GcS3/1