0

Using the code below will not add the query string 'section' to the link. The url adds just fine but what am i doing wrong with the query string?

@Html.Hidden("Url", Request.RawUrl)
@Html.Hidden("Query", sectionGroup.Term)

<a href="#" id="ajaxLink">@sectionGroup.Term</a>

<script>
  $("#ajaxLink").click(function () {     
    $.ajax({
      type: "POST",
      url: $("#Url").val(),
      data: { section : $("#Query").val() }
    }).done(function() {

    });
  });
</script>
3
  • You got confused between querystring and POST data. First decide what you want to pass, those are two different things. Commented Oct 29, 2013 at 13:42
  • I want to add a querystring to the url like: www.url.com/?section=value Commented Oct 29, 2013 at 13:47
  • So change to url: $("#Url").val() + "?section=value", Commented Oct 29, 2013 at 14:03

2 Answers 2

1

There are differences between GET and POST.

Take a look at this: What is the difference between POST and GET?

The code working is here: http://jsfiddle.net/felipemiosso/WtQsF/

javascript

$('#ajaxLink').click(function() {
    var $this = $(this);
    $this.attr('href', '?section=' + $('#query').val());
});

The code takes the existing href and replace it with the desired. Maybe you may need to adapt a little bit ...

Sign up to request clarification or add additional context in comments.

Comments

0

You will need to change the type: "POST" to type: "GET" for the query string to be passed.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.