单击按钮显示文件而不提交页面

时间:2018-08-24 13:23:13

标签: javascript php html button onclick

关于可见div,我需要显示大量文件。 基本上,我有以下格式的div,它们显示在下拉选择中。

@protocol MyProtocol <NSObject>
- (void)doStuffWithDictionary:(NSDictionary*)dict
                    andString:(NSString*)str1
            andOptionalString:(nullable NSString*)str2
             andOptionalArray:(nullable NSArray*)arr
                     callback:(void (^)(id result))onSuccess;
@end

所以我需要显示与可见div对应的文件。

此代码的问题是所有文件都在页面加载时加载,因此当文件数增加时页面数变慢。

因此,要解决此问题,我想在按钮上单击以加载内容。

我对此并不陌生,请提供帮助。

否则,我什至可以使用以下shell命令从网上获取数据

<div id="PRJNA252931" class="invisible" style="position: absolute; top: 60px; right: 50px; background-color: #f1f1f1; width: 480px; height:190px; padding: 10px; border: #0000cc 2px solid; border-radius: 5px; overflow:auto;">
<?php $file="PRJNA252931"; $content="<code><pre>".htmlspecialchars(file_get_contents("layout/files/Project_Detail/$file"))."</pre></code>";echo $content;?>
</div>

所以我不知道如何在不加载整个页面的情况下执行脚本,以及如何在替换按钮的同一个div中显示内容。

2 个答案:

答案 0 :(得分:0)

动态加载内容是JavaScript的理想方案。我们将使用新的Fetch API动态获取文件中的内容,并将其添加到框中。

self.request.user

答案 1 :(得分:0)

感谢加里,

是的,当我将按钮放置在php之外时,此方法有效。

<div id="PRJNA252931" class="inv" style="position: absolute; top: 60px; right: 50px; background-color: #f1f1f1; width: 480px; height:190px; padding: 10px; border: #0000cc 2px solid; border-radius: 5px; overflow:auto;">
<button type="button" name="PRJNA252931_btn" id="PRJNA252931_btn" onclick="loadFile(PRJNA252931_btn, 'layout/files/Project_Detail/PRJNA252931')">Load Detail</button>
</div>

我面临的唯一问题是所有数据都汇成一行。 this is the original file

This is how it is appearing

任何使标签和换行可见或设置显示数据样式的建议。