php - Ajax POST Requests return int instead of string -
i have following js code:
var datastring = "action=validateusername"+ "&username="+usernameregi+ "&lang="+lang; $.ajax({ type: "post", url: "function.php", data: datastring, cache: false, success: function(result) { var expl=result.split("|"); if(expl[0]=="1") alert("1"); else if(expl[0]=="99") alert("99"); } });
this function.php
if($_post["action"]=="validateusername") { $username=$_post["username"]; $lang=$_post["lang"]; $sqlselect = "select * user username='".$username."'"; $sqlquery = mysql_query($sqlselect); $rowcount = mysql_num_rows($sqlquery); if($rowcount>0) { if($lang=="bm") echo "99|my msga."; else echo "99|my msgb."; } else { if($lang=="bm") echo "1|my msgc."; else echo "1|my msgd."; } }
the problem is, ajax request never alert 1 or 99 on success. , found problem expl[0]==1 instead of expl[0]=="1".
when turn code one, run smooth.:-
if(expl[0]==1) alert("1"); else if(expl[0]==99) alert("99");
this happen when upload code server. no problem on localhost. problem, there setting on server cause problem?
could explain me, happening here?
it's because:
when assign numeric value variable, not put quotes around value. if put quotes around numeric value, treated text.
Comments
Post a Comment