我们用于某个软件的供应商有一个返回原始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的示例。
答案 0 :(得分:0)
如果你的意思是你想要构建js代码后端(虽然html页面使用js,它仍会加载前端)
PHP使用echo
这样:
,
或
echo "whatever you want to output";