1. 程式人生 > >關於Ajax傳多個引數的問題

關於Ajax傳多個引數的問題

最近都要自學程式碼了,上學不好好上,現在只能自己動手豐衣足食了

最近碰到的是關於頁面區域性更新,直接貼程式碼吧!

首先講一下傳單個引數

單個比較簡單,直接如下data寫法就好

  //區域性更新
        function up(ind){
            var url="/Spectaculars/Indexs?Ind="+ind;
            var data={type:1}; 
            $.ajax({
                type:"get",
                async:false,//同步請求
                url:url,
                data:data,
                timeout:1000,
                success:function (dates) {
                    $("#jumpUp").html(dates);

                },
                error:
                    function(){
                        alert("emmm...失敗");
                    }
            });
        }

再者是多個引數

多個引數時,資料data的格式有如下變化

採用鍵值對的方式

data:{
                    Id:"@sepLst[0].Id",
                    tableName:"@sepLst[0].tableName",
                },

值需要加上雙引號?不知道為什麼。。(笑哭)不加會在區域性更新上跳轉失敗。

 

  function up(){

            var url="/Spectaculars/[email protected][0].Id&[email protected][0].tableName";
            //alert(url);
            //var data={"Id":Id,"tableName":tableName};
            $.ajax({
                type:"get",
                async:false,//同步請求
                url:url,
                data:{
                    Id:"@sepLst[0].Id",
                    tableName:"@sepLst[0].tableName",
                },
                timeout:1000,
                //dataType:'json',//形式
                success:function (dates) {
                    $("#jumpUp").html(dates);

                },
                error:
                    function(){
                        alert("emmm...失敗");
                    }

            });
           
        }