最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Pass QueryString in window.location.href? - Stack Overflow

programmeradmin5浏览0评论

I have written the following javascript function

function getval(sel)
 {
    window.location.href = "Posts?Category=<%= sel %>";
 }

but the value of sel variable is not considered in querystring..

Instead of it, it takes value like following.

...../Post/Posts?Category=%3C%=%20sel%20%%3E

Can anyone help me???

I have written the following javascript function

function getval(sel)
 {
    window.location.href = "Posts?Category=<%= sel %>";
 }

but the value of sel variable is not considered in querystring..

Instead of it, it takes value like following.

...../Post/Posts?Category=%3C%=%20sel%20%%3E

Can anyone help me???

Share Improve this question asked Jul 15, 2013 at 11:23 Abhay AndhariyaAbhay Andhariya 2,1573 gold badges17 silver badges25 bronze badges 4
  • 1 Because .js files are not parsed by your back-end. – Fabrício Matté Commented Jul 15, 2013 at 11:25
  • Do you really need to wrap 'sel' in <%= %>? – Ben Gulapa Commented Jul 15, 2013 at 11:27
  • possible duplicate of how to pass parameter to javascript in asp – Fabrício Matté Commented Jul 15, 2013 at 11:28
  • Or would you want to use the the function argument sel to call a method on the back-end? In that case the principle applied is the same as stackoverflow./q/13840429/1331430 – Fabrício Matté Commented Jul 15, 2013 at 11:33
Add a ment  | 

2 Answers 2

Reset to default 7

Because javascript does not understands jsp scriptlet,

Try,

window.location.href = "Posts?Category=" + sel;

I don't know where you found this <%= sel %>, but its not the native JavaScript style of doing it. Try this:

function getval(sel)
{
    window.location.href = "Posts?Category=" + sel;
 }
发布评论

评论列表(0)

  1. 暂无评论