jquery ajax

 

    $.ajax({
            type: "post",
            url: "PersonalPortalService.ashx?Method=PersonalWidget_Add",
            async: false, //同步的ajax 并未异步
            data: { row: row, column: column},
            dataType: 'json',
            beforeSend: function (XMLHttpRequest) {

            },
            success: function (data, textStatus) {
                //var result = eval('(' + result + ')');
                
            },
            complete: function (XMLHttpRequest, textStatus) {
                //HideLoading();
            },
            error: function () {
                //请求出错处理
            }
        });

 

 JQuery的Ajax跨域请求的解决方案

 http://www.open-open.com/lib/view/open1334026513327.html

JQuery AJAX提交中文乱码的解决方案

http://www.mhzg.net/a/20113/2011398400802.html

jQuery的ajax 方法提交多个对象数组问题 C# traditional $.param

var arr1=[{ "aa": "1", "bb": "2" }, { "aa": "3", "bb": "4"}];

var arr2=[{ "aa": "1", "bb": "2" }, { "aa": "3", "bb": "4"}];


function addUser(){

        $.ajax({
            url:'UserAdd',
            data:$.param(arr1.serializeObject("list1"))+"&"+$.param(arr2.serializeObject("list2"),    //手动把数据转换拼接
            type:'post',
            traditional:true,    //这里必须设置
            success:function(msg){
                if(msg=='1'){
                    console.log('添加成功');
                }else{
                    console.log('添加失败')
                }
            }
        });
    }

 

 后台接收:

public class Test
    {
        public int aa{ get; set; }
        public int bb{ get; set; }
    }

        public ActionResult UserAdd( List<Test> list1, List<Test> list2)
        {
            
            return Json(amm);
        }

jsonp

一般处理程序内

     public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string method = context.Request["Method"].ToString();

            string callback = context.Request.QueryString["callback"]; // 用于jsonP的跨域调用。

            MethodInfo methodInfo = this.GetType().GetMethod(method);//利用反射 获取方法
            string result = methodInfo.Invoke(this, null).ToString();//执行获取到的方法
            if (string.IsNullOrEmpty(callback))
            {
                context.Response.Write(result);
            }
            else
            {
                context.Response.Write(callback + "(" + result + ")");
            }
        }

 

 

$.ajax({
        url: "http://127.0.0.1/Safety/HazardousChemicalsBusiness/T0130_EnerBaseInfoService.ashx?Method=GetT0130_EnerBaseInfo_IsAdmin&province=&city=&county=&town=&EnterpriseName=&PollutionType=&strEntList=&page=1&rows=3000&riskOrder=1",
        //&callback=callback
        type: "GET",
        dataType: "jsonp", //指定服务器返回的数据类型
        jsonp: "callback",   //指定参数名称 传递的就是callback这个参数 参数的value是随即的
        //jsonpCallback: "callback",  //指定回调函数名称
        success: function (data) {
            var result = JSON.stringify(data); //json对象转成字符串
            console.log(result);
            if(data){
                var html='';
                $.each(data.rows,function (index,row) {
                    html += '<tr>';
                    html+= '<td>' + (index + 1) + '</td>'
                    + '<td>' + row.C0130_Name + '</td>';// style="cursor:pointer;"
                    if(row.C0130_RiskLevelName){
                        html+= '<td>' + row.C0130_RiskLevelName + '</td>';
                    }else{
                        html+= '<td>--</td>';
                    }


                    html+= '</tr>';
                });
                $('#table_YingJiYuAn').append(html);
            }
        }
    });

 

posted @ 2013-11-10 18:36  高山-景行  阅读(297)  评论(0编辑  收藏  举报