从javascript函数打开一个php页面 [英] Open a php page from javascript function

查看:86
本文介绍了从javascript函数打开一个php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php页面,first.php,我想通过从javascript函数传递一些参数来打开页面。请帮助我,谢谢。

  function(){
var tableName =<?= $ p ?>中; //从另一个php文件获取值
var checkB = checkbox_form.checkbux [counter] .value;
window.open('http://localhost/first.php?q =+ checkB +& p =+ tableName','_self');
}

但我无法打开页面,请帮忙。在前面的回答中,你可以很容易地使用 window.location code>打开一个PHP页面;但是,当使用 encodeURIComponent() JavaScript函数时,您应该始终记住在URL中使用它们时转义您的变量:

  window.location =http://localhost/first.php?q =+ encodeURIComponent(checkB)+& p =+ encodeURIComponent(tableName); 


I have a php page, first.php and I want to open the page with passing some arguments from a javascript function. Could you please help me, thanks.

function() {
    var tableName = "<?= $p ?>"; //obtaining the value from another php file
    var checkB = checkbox_form.checkbux[counter].value;
    window.open('"http://localhost/first.php?q="+checkB+"&p="+tableName', '_self');
}

But I am not able to open the page, please help. Thanks in advance.

解决方案

As the previous answers state, you could easily use window.location to open a PHP page; however, you should always remember to escape your variables when using them in a URL, using the encodeURIComponent() JavaScript function:

window.location = "http://localhost/first.php?q=" + encodeURIComponent(checkB) + "&p=" + encodeURIComponent(tableName);

这篇关于从javascript函数打开一个php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆