AJAX和iFrame:从iFrame内部调用AJAX来更新外部DIV

时间:2023-01-05 23:59:25

I have a page where a user can upload a file along with some other input. Because I wanted this to be AJAX-like, I resorted to using an iFrame to accomplish this.

我有一个页面,用户可以上传文件和其他一些输入。因为我希望它像AJAX一样,我使用iFrame来实现这一点。

After the file is uploaded and an iFrame is loaded with a response page, I need to update a DIV outside of the iFrame with an AJAX call. The reason for separate updates, is that the result of the outside DIV depends on the input that the user provided with the file input.

上传文件并使用响应页面加载iFrame后,我需要使用AJAX调用更新iFrame之外的DIV。单独更新的原因是外部DIV的结果取决于用户提供的文件输入的输入。

Can this be done? Am I approaching this the wrong way?

可以这样做吗?我接近这个错误的方式了吗?

Thank you!

谢谢!

UPD: Can the returned client code from within the iFrame "see" elements outside that iFrame?

UPD:iFrame中返回的客户端代码可以“看到”iFrame之外的元素吗?

2 个解决方案

#1


0  

Write your code in the onload event of the page loaded into the iframe. Then top will give you the top frame or parent will give you the parent frame.

将代码写入加载到iframe中的页面的onload事件中。然后top将为您提供顶部框架,或者父级将为您提供父框架。

#2


0  

Yes , it can be done. But you can do away with,the need for an AJAX-call , to update the outside the div.

是的,可以做到。但是你可以不需要AJAX调用来更新div的外部。

Have your, servlet(assuming you are using JSP/servlets) that accepts the mutlipart request(the servlet that accepts the upload), return the intended response (to be shown on the refreshed iFrame), and ALONG WITH IT, the necessary information from the file input. This way you have all the necessary details on the client, in one response. A simple javascript function can achieve , updating the outer div with the information from the file input.

让你的servlet(假设你正在使用JSP / servlet)接受mutlipart请求(接受上传的servlet),返回预期的响应(显示在刷新的iFrame上),以及ALONG WITH IT,来自的必要信息文件输入。通过这种方式,您可以在一个响应中获得客户端上的所有必要详细信息。一个简单的javascript函数可以实现,用文件输入中的信息更新外部div。

#1


0  

Write your code in the onload event of the page loaded into the iframe. Then top will give you the top frame or parent will give you the parent frame.

将代码写入加载到iframe中的页面的onload事件中。然后top将为您提供顶部框架,或者父级将为您提供父框架。

#2


0  

Yes , it can be done. But you can do away with,the need for an AJAX-call , to update the outside the div.

是的,可以做到。但是你可以不需要AJAX调用来更新div的外部。

Have your, servlet(assuming you are using JSP/servlets) that accepts the mutlipart request(the servlet that accepts the upload), return the intended response (to be shown on the refreshed iFrame), and ALONG WITH IT, the necessary information from the file input. This way you have all the necessary details on the client, in one response. A simple javascript function can achieve , updating the outer div with the information from the file input.

让你的servlet(假设你正在使用JSP / servlet)接受mutlipart请求(接受上传的servlet),返回预期的响应(显示在刷新的iFrame上),以及ALONG WITH IT,来自的必要信息文件输入。通过这种方式,您可以在一个响应中获得客户端上的所有必要详细信息。一个简单的javascript函数可以实现,用文件输入中的信息更新外部div。