-1
我有一个问题,我有一个JavaScript代码,其中包含我想动态显示在我的html页面上的东西。 而动态内容的一部分需要从php脚本中获得,所以我听说我必须使用j query或ajax来调用javascript内部的php文件,获取它的回响,然后显示使用回显的内容j查询/ ajax/javascript到网页。 这就是我想要做的,仅仅是一个例子。调用并打印php脚本通过jquery返回
PHP文件(包含在helloworld.php):
<?php
Echo "hello world";
?>
HTML:
<html>
<body>
<script src="credits.js"/>
</body>
</html>
JS(credits.js):
Document.writeln("The example message for today is:"+
"<script language='javascript'>"+
"$.post('helloworld.php', { var1: "blah" }, function(data) {"+
"$('#div_content').html(data);"+
"});"+
"</script>");
我真的很沮丧因为无论我试图让js调用php页面,只显示该回声的该死的内容,它只是不工作... 我做错了什么?
为什么使用document.write? – Gavin
请不要使用'document.write'。特别是,没有必要直接编写一个内联脚本来“执行”代码。 –
您需要在您的HTML –