困惑于ajax成功功能

时间:2011-05-19 04:07:21

标签: php javascript jquery ajax

我有一些用于检查用户的服务器端脚本:

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;
}

之后如果该脚本获得结果为“3”,它将返回到ajax成功函数。然后做下一个工作,如果显示结果为“3”它将向另一个变量发送一些值。

$.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);
            }
        });

但是,它不起作用,我没有收到任何错误消息。我的ajax是否错了?


我也在ajax里面有ajax。 div id= app inside a cell below "issue by"

1 个答案:

答案 0 :(得分:0)

您的switch获得了一个号码,但您的case是一个字符串:

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

如果没有对代码进行任何其他修复,则应将其更改为

switch(parseInt(res)){
    case 3: