Bader H Al Rayyes
Bader H Al Rayyes

Reputation: 522

passing url variable with my jquery script to the serverside file

i have a pagination script which working with jquery and php scripts, i am trying here to pass a url variable called rev in my url which give the pagination server side file a sql id parameter

here is my jquery code:

function loadData(page){
                    loading_show(); 

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

                        success: function(msg)
                        {

i tried the following but it did not work

function loadData(page){
                    loading_show(); 

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

                        success: function(msg)
                        {

which it did not work , how can i get the variable from the URL then pass it through the jquery to my server side file ?

Upvotes: 0

Views: 198

Answers (3)

Maverick
Maverick

Reputation: 2760

Well, Here is the complete code you are looking for:

 $.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);


                        }

                        }); 

Now for your thing:

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

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

Upvotes: 0

Zhonk
Zhonk

Reputation: 634

You may use an Object as the data attribute

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

Upvotes: 3

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175098

You need an object:

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

Though you might want to rename your variables so that you won't be confused.

Upvotes: 1

Related Questions