jquery - dynamically value inside javascript src url - Stack Overflow

I'd like to put a javascript variable value dynamically inside to a script src url. <head runat

I'd like to put a javascript variable value dynamically inside to a script src url.

<head runat="server">
 <script type="text/javascript">
    var id = $("[id$='hfProductIdList']").val();
 </script>
 <script type="text/javascript" src="https://test/tr.aspx?orderid=id">
 </script>    
</head>

If there is a way to set up these value dynamicly It would be great for me.

I'd like to put a javascript variable value dynamically inside to a script src url.

<head runat="server">
 <script type="text/javascript">
    var id = $("[id$='hfProductIdList']").val();
 </script>
 <script type="text/javascript" src="https://test/tr.aspx?orderid=id">
 </script>    
</head>

If there is a way to set up these value dynamicly It would be great for me.

Share Improve this question edited May 9, 2013 at 8:41 baros asked May 9, 2013 at 8:35 barosbaros 2512 gold badges9 silver badges23 bronze badges 1
  • what are you trying to do here? if you want to send file to server side script (in this case asp) use ajax. you are giving asp page as source where it is expected js (because you use type = javascript) – Bojan Kovacevic Commented May 9, 2013 at 8:39
Add a ment  | 

2 Answers 2

Reset to default 4

You can simply do this:

var id = $("[id$='hfProductIdList']").val();
$('head').append('<script type="text/javascript" src="https://test/tr.aspx?orderid=' + id + '" />');

You need to append it using pure javasript;

var id = $("[id$='hfProductIdList']").val();
var jsElem = window.document.createElement('script');
jsElem.src = 'https://test/tr.aspx?orderid=' + id;
jsElem.type = 'text/javascript';
$('head').append(jsElem);

Also it might be better idea to append it to body rahter than head, but it's not a subject of your question.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745161306a4614401.html

相关推荐

  • jquery - dynamically value inside javascript src url - Stack Overflow

    I'd like to put a javascript variable value dynamically inside to a script src url. <head runat

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信