art.dialog 与jquery ajax请求问题

来源:互联网 发布:男士风衣 知乎 编辑:程序博客网 时间:2024/05/21 18:23

 

1、在开发项目时候,我们需要先进行jquery.ajax请求,可是我们用常规的$.post,$.get在function中进行art.dialog.close会发生报错,报错为jquery 的

type: function (obj) {
                return obj == null ?
   String(obj) :
   class2type[toString.call(obj)] || "object";
            },

报String未定义,TMMD搞了半天不晓得是怎么回事,以为是jquery版本问题,我由jquey-1.6.2.js换到jquery-1.11.0.js都不行。后来我不在异步请求后进行执行art.dialog.close正常执行没有问题,则说明是jquery ajax出了问题,于是把$.post,$.get换成原生的$.ajax在 success中进行执行,成功了。

以下编写的代码,希望对后来开发遇到此问题的朋友作以参考。

$.ajax({
                    type: "post",
                    url: "SysDictionaryManageH.ashx",
                    data: { "action": "MoveDic",
                        "PID": pid,
                        "ID": id,
                        "rand": Math.random()
                    },
                    dataType: "text",
                    async: false, //加上这个,使之同步。
                    success: function (result) {
                        AlertFun(result);
                    },
                    error: function (json) {
                        alert(json);
                    }
                });

注意事项:AlertFun(result); 如果是用$.post $.get在请求完后,得到不result

如:

     var temp='';
$.post("SysDictionaryManageH.ashx", { "action": "QueryMoveDic", "iLayer": "0", "MoveID": art.dialog.data("id") }, function (result) {
                if (result) {
                   temp=result;
                }
            });
alert(temp)这里是得不到值的,但是用$.ajax就可以。

 

 

 

0 0
原创粉丝点击