dongshao8125 2011-11-10 03:47
浏览 44

如何在PHP中将URL变量传递给javascript

I need to take a URL variable into a PHP page, and then later pass it into some javascript that's in HTML later in the page. Here's where I need to use the variable:

function dosubmit( ) {
new Ajax.Updater( 'result', 'dial.php', { method: 'post' , parameters: $('dialer').serialize() } );
$('dialer').reset();
}

the URL variable is formatted as dialout.php?ext=1234. It is stored in PHP as $ext. result is the div that returned html will be placed in, and dialer is a form that a user would enter a phone number into; I need to pass it along with the $ext variable to dial.php. My thought was to concatenate the two, as

var ext = "<? $uext ?>";
var par = $('dialer').serialize();
var url = par;

and then using url in place of $('dialer').serialize(). This does not work, though; dial.php reports never gets the ext variable. What's the best way to move a URL variable into PHP, then into js, then post it back to PHP? I apologize in advance if I've mis-explained something, this is all new to me.

Thanks!

  • 写回答

3条回答 默认 最新

  • douchui4815 2011-11-10 03:51
    关注

    You have the right idea, but you need to use a command like print or echo to populate the variable:

    var ext = "<? echo $uext ?>";
    

    Otherwise $uext by itself as a PHP statement effectively does nothing.

    Also, you need to include the ext variable into your parameter list. Your current code as it stands doesn't make any further references to ext after it is populated:

    var par = $('dialer').serialize();
    par += '&ext=' + ext;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多