开发者

Confusing in ajax success function

I have some serverside script for check user:

function passlog($use,$pass){
        $Use = mysql_real_escape_string($use);
        $Pass= mysql_real_escape_string($pass);
$res=mysql_query($sql) or die(_ERROR26.":".mysql_error());
  $dat=mysql_fetch_array($res,MYSQL_NUM);  //it will get result ex. "3"
        if(mysql_affected_rows()>0) {
                        echo $dat[0];
                        }else{
                        echo "No specified data";
        }
return 0;
}

after that if that script get result as "3" it will return to ajax success function. Then do the next job, there is if show result as "3" It will send some value to another variable.

$.ajax({
        type:"post",
        url:"process3.php",
        data:params,
        cache:false,
        async:false,
        success: function(res){
                               $("#dialog").dialog('close');
                               var now = new Date();
                               var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
                               var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
                               function fourdigits(number) {
                                         return (number < 1000) ? number + 1900 : number;
                                         }
                               var today =  months[now.getMonth()] + "/" +date+ "/" + (fourdigits(now.getYear()));

                               switch(parseInt(res)){
                                     case "3":
                                               $("#appdate").text(today);         //not work
                                               $("#app").text($("#user").val()); //not work
                                               break;
                          }
                            $.ajax({
                                    type:"post",
                                    url:"process1.php",
                                    data:"tversion="+matches+"&action=tunermatches",
                                    cache:false,
                                    async:false,
                                    success: function(res){
                                                 $('#tunedat').replaceWith(
                                                                                    "<div id='tunedat'><h6>" + res + "</h6></div>"
                开发者_运维百科                                                  );
                                                 }
                                     });
                },
    error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(thrownError);
            }
        });

but, its not work and i get no error message. Whether my ajax wrong?


i have ajax inside ajax too.

Confusing in ajax success function


Your switch gets a number but your case is for a string:

switch(parseInt(res)){
    case "3":

Without any other fixes to your code, this should be changed to

switch(parseInt(res)){
    case 3:
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜