简体   繁体   English

将参数从php传递到javascript,再传递回php

[英]passing a parramter from php to javascript back to php

I have a php page, which using javascript, creates a popup window which contains another php page. 我有一个PHP页面,使用javascript创建了一个包含另一个PHP页面的弹出窗口。 the php page in the popup window is basically a form, and will use that value to insert into a database. 弹出窗口中的php页面基本上是一种表单,并将使用该值插入数据库。 Using the following function to load the php page in a popup: 使用以下函数在弹出窗口中加载php页面:

phppopup('edit_status.php?cmd=EditStatusData')

function phppopup(page){
child1 = window.open (page, "Ebay Auctions", "height=600,width=600,status=yes,toolbar=no,menubar=no,location=no");
child1.document.close(); 
}

How can i pass a value from the calling page to the page in the popup? 如何将值从调用页面传递到弹出窗口中的页面?

I am trying at the moment: 我目前正在尝试:

echo "<p><a href=\"#\" onclick=\"updateByEdit('". $username ."', '". $subcat ."')\">Edit User Info</a>
<p><a href='#' onclick=\"makewindows2('edit_status.php?cmd=EditStatusData&pk=". $pk ."'); return false;\">Historie</a>;

Which generates the following html: 生成以下html:

<a href="#" onclick="updateByEdit('trendsandbrands', 'fakeapproved')">Edit User Info</a>
</strong></strong></strong></strong></p><p><strong><strong><strong><strong><a href="#" onclick="phppopup('edit_status.php?cmd=EditStatusData&amp;pk='); return false;">Historie</a>

It works fine for updateByEdit, why not for phpopup? 它适用于updateByEdit,为什么不适用phpopup?

$pk is just an integer, which display fine in the page it the window is called from. $ pk只是一个整数,在调​​用该窗口的页面上可以很好地显示。

Well, you're already doing it - the GET variable in edit_status.php will have one entry, with key='cmd' and value='EditStatusData'. 好了,您已经在做-edit_status.php中的GET变量将只有一个条目,键='cmd'和value ='EditStatusData'。 Just pass as many parameters as you need (while being mindful that such data will be publicly viewable). 只需根据需要传递尽可能多的参数(请注意,这些数据将是可公开查看的)。

Just add the arguments as part of the get request: 只需将参数作为get请求的一部分添加:

phppopup("index.php?var1=value1&var2=value2"); // Get

etc. 等等

Alternatively, for passing it arguments when it is open already, use the handle that is returned (child1) and access that window's DOM via javascript. 另外,要在打开时传递参数,请使用返回的句柄(child1)并通过javascript访问该窗口的DOM。

child1.document.getElementById("myelement").innerHTML = "Hello World"; // Parent Child

If you have trouble with this, get the child window to trigger a callback in the parent window via window.opener when the child document has loaded, eg 如果您对此有疑问,请在加载了子文档后,使子窗口通过window.opener在父窗口中触发回调,例如

window.opener.myCallback(requestedinfo); // Parent window callback function

I noticed that the generated HTML contains a query string that has HTML entities ('& amp;') instead of their actual equivalents. 我注意到生成的HTML包含一个查询字符串,该字符串具有HTML实体(“&amp;”),而不是它们的实际等效物。 Make sure that updateByEdit(...) isn't returning entities or the query string won't be printed correctly. 确保updateByEdit(...)没有返回实体,否则查询字符串将无法正确打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM