基本的JQuery / Ajax帖子帮助

时间:2011-07-23 04:12:36

标签: php jquery ajax

我正在学习PHP,我不知道如何让它工作。我需要帮助编写返回此JQuery $ .post()

的数据的文件

我不知道如何使用firebug,但Firefox的错误控制台显示“错误:找不到元素”

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title>JQuery Test</title>
</head>

<body>

<a class="open" href="#" style="color:black; text-decoration:none;">Test File</a>

<br />

<pre id="Test">Hello</pre>

<script type="text/javascript">
$('.open').click(function(){
$.post('source.php', function(src){
    alert(src)
    $('#Test').html(src);
});
return false;
});
</script>
</body>
</html>

PHP文件

<?php
echo "hi"
?>

2 个答案:

答案 0 :(得分:1)

测试ID选择器错误,请尝试以下

<script type="text/javascript">
$('.open').click(function(){
$.post('source.php', function(src){
    alert(src)
    $('#Test').html(src);
});

/*
$.post('source.php', {name: current}, function(src){
    codeBox.html(src);
});
*/

return false;
});
</script>

答案 1 :(得分:0)

您的脚本中存在许多缺陷。

The **$('Test').html(src);** will not work it should be **$('#Test').html(src);**

The **<?php>** should be just **<?php**
相关问题