与我的jQuery脚本传递网址变量到服务器端文件

问题描述:

我有一个分页脚本,它使用jQuery和PHP脚本,我想在这里传递一个url变量,在我的url中传递rev这给了分页服务器端文件一个SQL id参数与我的jQuery脚本传递网址变量到服务器端文件

这里是我的jQuery代码:

function loadData(page){ 
        loading_show(); 

        $.ajax 
        ({ 
         type: "POST", 
         url: "commentPagination.php", 
         data: "page="+page, 

         success: function(msg) 
         { 

我尝试以下,但它没有工作

​​

它没有活像k,我如何从URL获取变量,然后通过jquery传递给我的服务器端文件?

的数据属性

//... 
    data: { 
     page: page, 
     rev: rev 
    }, 
//... 

你需要一个对象:

data: {page: page, rev: rev}, 

虽然你可能要重命名变量,这样你就不会混淆。

那么你可以使用一个对象,这是你正在寻找的完整代码:

$.ajax({ 
          type: "POST", 
          url: "get-cities-xml/"+area, 
          data: "eid=0", 
          dataType: "xml", 
          success: function(data) { 
           $html = ""; 
           $(data).find("city-name").each(function(){ 
            $html += "<li><a class='aclick' href='getproperty/"+$(this).find("name").text()+"'>"+$(this).find("name").text()+"</a></li>"; 

           }); 
           $("#show-cities").html("<ul>"+$html+"</ul>"); 
          }, 
         error:function(xhr,err){ 
          //alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); 
         alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); 


         } 

         }); 

现在对于你的事:

$.ajax 
        ({ 
         type: "POST", 
         url: "commentPagination.php", 
         data: "page="+page, 

         success: function(msg) 
         { 
alert(msg)// that msg contains ur html response. 
},