0

How do you pass values from a link like this to a function <a href="search=sony&offset=20&lang=en" class="more_info">Read More</a> This link isn't static and values change depending on the search term and page number.

When a user clicks this link, it sends those 3 values to demo_search.php. Results are returned as html. Only a div on the page is refreshed.

I cant figure out how to get those values to the data part in the function. Can you please help me with that.

$(function() {

    $(".more_info").click(function() {
            // ajax call
            $.ajax({
                type: "GET",
                url: "demo_search.php",
                data: Need help in getting those values from the href here,
                beforeSend: function(html) {

                    $(".imgProgress").html(imgLoad);

                },
               success: function(page_data){

                    $("#results").empty();
                    $("#results").append(page_data);
                    $(".imgProgress").empty();
              },

            });    
        }
        return false;
    });
});
2
  • 1
    you should be able to do: data: this.href since your href contains data that can be directly placed into the data option. Commented Jul 23, 2012 at 14:56
  • Possible duplicate to : stackoverflow.com/questions/2090551/… Commented Jul 23, 2012 at 15:01

3 Answers 3

3

try:

url: "demo_search.php?"+$(this).attr("href"),
Sign up to request clarification or add additional context in comments.

1 Comment

Personally I'd make the href attribute the full URL, rather than just the query string, then do url: this.href, but this way works too.
2

When calling $.ajax(), you can actually pass the data as a query string, so

data : this.href 

should work.

Comments

0

try this

$(function() {

    $(".more_info").click(function() {
            var targetLink = this;
            $.ajax({
                type: "GET",
                url: "demo_search.php?"+$(targetLink).attr("href"),
                beforeSend: function(html) {

                    $(".imgProgress").html(imgLoad);

                },
               success: function(page_data){

                    $("#results").empty();
                    $("#results").append(page_data);
                    $(".imgProgress").empty();
              },

            });    
        }
        return false;
    });
});​

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.