首页 新闻 会员 周边

js jquery大侠帮我封装下这个吧

0
悬赏园豆:15 [已解决问题] 解决于 2012-08-20 17:07
 /*ajax查询*/
        $(Jquery).click(function () {
            ajax_function({
                type: "GET",
                url: "/WC_Index/Ajax_Index",
                data: "name=" + txtname.val(),
                dataType: "json",
                success: ????????这个我不会封装 
            });
            //
        });
//ajax
function ajax_function(obj) {
    $.ajax({
        type: obj.type,
        url: obj.url,
        data: obj.data, 
        dataType: obj.dataType,
        success: obj.success
    });
}
//ajax success
function ajax_success(obj) {
    $("#listTabe li").remove();
     var resultHtml = '';
     $.each(obj.data, function (i, n) {
        resultHtml += '<li><a id="MeauID" href="/WC_Index/UrlJquery/' + n.CustomerID + '">' + n.Customer_Name + '</a></li>';
    });
    $("#listTabe").html(resultHtml);
}

还有这样封装我觉得还是有 type: url

ajax_function({
                type: "GET",
                url: "/WC_Index/Ajax_Index",
                data: "name=" + txtname.val(),
                dataType: "json",
                success: ????????这个我不会封装 


封装后如何去掉这些呢?第一次搞这个封装 所以 有点不会 大侠们

s_p的主页 s_p | 初学一级 | 园豆:138
提问于:2012-08-14 10:46
< >
分享
最佳答案
0
var Obj=new function()
{
     //声明一些变量
     this.url='';
     this.datatype='';
}

obj.prototype.success=function() {  .....    }
obj.prototype.其它=function() {..........}


//应用

var s=new Obj();
Obj.url='';
Obj.datatype='';

$.ajax({
type:s.type,
url:s.url,
success:s.success
});

 

好像大致是这一个样子的  不足之处楼主在查看下相关资料

收获园豆:7
havid | 初学一级 |园豆:70 | 2012-08-20 13:12
其他回答(1)
0

Jquery已经封装过Ajax提交查询了,你的

function ajax_function(obj){} 没有意义啊 
你可以下面的方法写,不知道时你想要的不?
$(Jquery).click(function () {  
$(jquery).ajax({
   type: "get",
   url: "/WC_Index/Ajax_Index", 

data: "name=" + txtname.val(),
  dataType: "json",
success: function(obj){ 
 $("#listTabe li").remove();
     var resultHtml = '';
     $.each(obj.data, function (i, n) {
        resultHtml += '<li><a id="MeauID" href="/WC_Index/UrlJquery/' + n.CustomerID + '">' + n.Customer_Name + '</a></li>';
    });
    $("#listTabe").html(resultHtml);


} });
//  });
 建议楼主看下jquery.ajax 的方法
收获园豆:8
acepro | 园豆:1218 (小虾三级) | 2012-08-15 09:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册