0

On the current page I have a Query String set as ~/Item.aspx?ItemId=somevalue Now I want to append it to the url inside the jquery.

<script type="text/javascript">
    $(function () {
        $('#testRater').rater({ postHref: 'RatingHandler.ashx?ItemId=' + somevalue });
    });
     </script>

I am new to jquery and I'v been searching all around the web for this solution but can't find one. Please Guide me to the way to do so. Or is it possible to use the query string of .aspx page in .ashx??

Manish Gor
  • 3
  • 1
  • 3
  • Do you want to send the query to `Item.aspx` or `RatingHandler.aspx`? – Sudipta Chatterjee Feb 24 '14 at 21:21
  • Also, `rater` isn't a standard jQury function - is that what you wanted to use? – Sudipta Chatterjee Feb 24 '14 at 21:30
  • I want to append the current url's Query string i.e "ItemId" to the Url inside the jquery – Manish Gor Feb 24 '14 at 21:30
  • By appending "inside the jquery" (which isn't syntactically accurate, btw) - you mean you want to extract the `ItemId` from the query string variable you have locally and then append it to your `postHref` call? – Sudipta Chatterjee Feb 24 '14 at 21:33
  • yes, that is exactly what I wish to do, I have edited the question. – Manish Gor Feb 24 '14 at 21:38
  • between I have found out the way, that is to save a cookie with the value of the query string and retrieve it in the handler. But that alerts my anti virus for malicious activity. So that might not be the perfect way to do it, I guess this can be done using jquery only. – Manish Gor Feb 24 '14 at 21:41
  • possible duplicate of [How can I get query string values in JavaScript?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – CBroe Feb 24 '14 at 21:53
  • Can you please mark my answer as correct if it worked for you? – Sudipta Chatterjee Feb 25 '14 at 22:59

2 Answers2

0

Assuming you have the queryString variable already set,

<script type="text/javascript">
var queryString = "~/Item.aspx?ItemId=somevalue";
var splitQuery = queryString.split("="); //
$(function () {
    $('#testRater').rater({ postHref: 'RatingHandler.ashx?ItemId=' + splitQuery[1] });
});
 </script>

A potential caveat is that I am assuming the queryString is always going to be something like blah=value and I am splitting by the equal sign. Multiple parameters would need to be handled differently.

Sudipta Chatterjee
  • 4,592
  • 1
  • 27
  • 30
0

You can use the following script:

 $(function () {
        $('#testRater').rater({ postHref: 'RatingHandler.ashx?item=<%=Request.QueryString["item"] %>' });
    });
ρss
  • 5,115
  • 8
  • 43
  • 73