从javascript函数打开一个php页面

从javascript函数打开一个php页面,php,javascript,function,Php,Javascript,Function,我有一个php页面first.php,我想通过从javascript函数传递一些参数来打开该页面。你能帮帮我吗,谢谢 function() { var tableName = "<?= $p ?>"; //obtaining the value from another php file var checkB = checkbox_form.checkbux[counter].value; window.open('"http://localhost/firs

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

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');
}
function(){
var tableName=”“;//从另一个php文件获取值
var checkB=checkbox\u form.checkbux[counter]。值;
窗口。打开(“”“http://localhost/first.php?q=“+checkB+”&p=“+tableName',“\u self”);
}
但是我无法打开页面,请帮助。提前感谢。

使用

document.location = 'http://localhost/first.php?q='+checkB+'&p='+tableName;
使用


这比你想象的要简单

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

这比你想象的要简单

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

正如前面的回答所述,您可以轻松地使用
window.location
打开一个PHP页面;但是,在URL中使用变量时,应始终记住使用
encodeURIComponent()
JavaScript函数转义变量:

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

正如前面的回答所述,您可以轻松地使用
window.location
打开一个PHP页面;但是,在URL中使用变量时,应始终记住使用
encodeURIComponent()
JavaScript函数转义变量:

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

我的理解是,您需要打开另一个带有一些动态参数的选项卡或弹出窗口。 我有两种解决方案:

1-将一些额外的JS附加到锚用户将使用onMouseOver()事件单击,并向href提供计算出的URL。目标必须设置为“\u blank”

例如:

<a href="whateverPage.php" target="_blank" onMouseOver="this.href='myPage.php?myParam=' + myParamValue;">Goto new page</a>

请注意,在本例中,“myParamValue”需要是全局的

2-您想在ajax请求后打开新选项卡或弹出窗口吗?在我的例子中,我希望在服务器上生成一个新的报告PHP页面,并立即打开它。以前的解决方案没有帮助

以下是我愚弄弹出窗口拦截器的解决方案:

//this generates the new report page 
report = new ajaxReq("gentabrep.php", ajaxCallBackFunction);
//open the pop-up on user action/event which is normally allowed
w = window.open("", "");
//run ajax request, note I also pass the "w" pop-up reference to the request
report.request("connId=" + connId + "&file=" + file, "POST", [w, file]);

function ajaxCallBackFunction(returnedStr, status, params){
  //I feed the pop-up with the necessary javascript to redirect the page immediately
  params[0].document.writeln("<scr"+"ipt type='text/javaScript'>window.location='reports/" + params[1] + ".php';</scr"+"ipt>");
}
//这将生成新的报告页
report=newajaxreq(“gentabrep.php”,ajaxCallBackFunction);
//打开通常允许的用户操作/事件弹出窗口
w=窗口。打开(“,”);
//运行ajax请求,注意我还将“w”弹出引用传递给请求
report.request(“connId=“+connId+”&file=“+file,”POST“,[w,file]);
函数ajaxCallBackFunction(返回的str、状态、参数){
//我向弹出窗口提供必要的javascript,以便立即重定向页面
params[0]。document.writeln(“window.location='reports/”+params[1]+.php';”;
}

我的理解是,您需要打开另一个选项卡或带有一些动态参数的弹出窗口。 我有两种解决方案:

1-将一些额外的JS附加到锚用户将使用onMouseOver()事件单击,并向href提供计算出的URL。目标必须设置为“\u blank”

例如:

<a href="whateverPage.php" target="_blank" onMouseOver="this.href='myPage.php?myParam=' + myParamValue;">Goto new page</a>

请注意,在本例中,“myParamValue”需要是全局的

2-您想在ajax请求后打开新选项卡或弹出窗口吗?在我的例子中,我希望在服务器上生成一个新的报告PHP页面,并立即打开它。以前的解决方案没有帮助

以下是我愚弄弹出窗口拦截器的解决方案:

//this generates the new report page 
report = new ajaxReq("gentabrep.php", ajaxCallBackFunction);
//open the pop-up on user action/event which is normally allowed
w = window.open("", "");
//run ajax request, note I also pass the "w" pop-up reference to the request
report.request("connId=" + connId + "&file=" + file, "POST", [w, file]);

function ajaxCallBackFunction(returnedStr, status, params){
  //I feed the pop-up with the necessary javascript to redirect the page immediately
  params[0].document.writeln("<scr"+"ipt type='text/javaScript'>window.location='reports/" + params[1] + ".php';</scr"+"ipt>");
}
//这将生成新的报告页
report=newajaxreq(“gentabrep.php”,ajaxCallBackFunction);
//打开通常允许的用户操作/事件弹出窗口
w=窗口。打开(“,”);
//运行ajax请求,注意我还将“w”弹出引用传递给请求
report.request(“connId=“+connId+”&file=“+file,”POST“,[w,file]);
函数ajaxCallBackFunction(返回的str、状态、参数){
//我向弹出窗口提供必要的javascript,以便立即重定向页面
params[0].document.writeln(“window.location='reports/”+params[1]+.php';”;
}

我尝试了以上三种方法,但结果页面与调用函数时附加变量的页面相同。从到,我尝试了以上三种方法,但结果页面与调用函数时附加变量的页面相同。从到不使用escape()/unescape()。有适合不同用途的适当功能。在这种情况下,encodeURIComponent是合适的。不要使用escape()/unescape()。有适合不同用途的适当功能。在这种情况下,encodeURIComponent是合适的。