Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有哪些选项可以呈现Javascript;文件。写下“;用PHP编写服务器端代码?_Javascript_Php_Server Side_Server Side Rendering - Fatal编程技术网

有哪些选项可以呈现Javascript;文件。写下“;用PHP编写服务器端代码?

有哪些选项可以呈现Javascript;文件。写下“;用PHP编写服务器端代码?,javascript,php,server-side,server-side-rendering,Javascript,Php,Server Side,Server Side Rendering,我们用于软件的供应商有一个返回原始javascript的API。其目的是使用API作为源的脚本标记。我们较小的页面有70多个客户端请求,用所有必需的数据填充页面。响应如下所示: document.write("\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/Ev

我们用于软件的供应商有一个返回原始javascript的API。其目的是使用API作为源的脚本标记。我们较小的页面有70多个客户端请求,用所有必需的数据填充页面。响应如下所示:

document.write("\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23719&information_id=38921&type=&syndicate=syndicate\" target=\"blank\" \u003e8/28\u003c/a\u003e\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"cinfo home_event_decs\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23719&information_id=38921&type=&syndicate=syndicate\" target=\"blank\" \u003eGetting Started with Next Generation Classrooms - Incubator Classroom\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23756&information_id=39010&type=&syndicate=syndicate\" target=\"blank\" \u003e8/28\u003c/a\u003e\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"cinfo home_event_decs\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23756&information_id=39010&type=&syndicate=syndicate\" target=\"blank\" \u003eGmail and Calendar Tips and Tricks\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23752&information_id=38995&type=&syndicate=syndicate\" target=\"blank\" \u003e8/28\u003c/a\u003e\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"cinfo home_event_decs\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23752&information_id=38995&type=&syndicate=syndicate\" target=\"blank\" \u003eCreating Accessible and Fillable Electronic Forms\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23720&information_id=38923&type=&syndicate=syndicate\" target=\"blank\" \u003e8/28\u003c/a\u003e\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"cinfo home_event_decs\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23720&information_id=38923&type=&syndicate=syndicate\" target=\"blank\" \u003eGetting Started with Next Generation Classrooms - General\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv class=\"cal home_events\"\u003e\u003cdiv class=\"cdate blue\"\u003e\u003cp class=\"date\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23881&information_id=39283&type=&syndicate=syndicate\" target=\"blank\" \u003e8/28\u003c/a\u003e\u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"cinfo home_event_decs\"\u003e\u003ca href=\"http://events.sjsu.edu/EventList.aspx?view=EventDetails&eventidn=23881&information_id=39283&type=&syndicate=syndicate\" target=\"blank\" \u003eComedySportz Improv Show\u003c/a\u003e\u003c/div\u003e\u003c/div\u003e");

如您所见,DOM结构正在构建并打印到调用它的页面。我想做的是呈现响应服务器端,以获得更平滑的用户体验。我们正在后台运行PHP。我不确定V8js是否是一种解决方案-我找不到任何使用
document.write
或在React上下文之外使用V8js的示例

如果您的意思是要构建js代码后端(它仍然会加载前端,就像html页面使用js一样)

PHP使用echo

因此:

$output=“$(document.ready(function()){
警报(“hi”);
});"
echo$输出;

替换
文档。用
echo
写入
echo "whatever you want to output";
$output = "<script>$(document.ready(function(){
alert('hi');
});</script>"

echo $output;