首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >基本JQuery/Ajax post帮助

基本JQuery/Ajax post帮助
EN

Stack Overflow用户
提问于 2011-07-23 12:12:36
回答 2查看 187关注 0票数 0

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

我不知道如何使用firebug,但是Firefox的错误控制台显示" error : no element found“

代码语言:javascript
复制
<!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文件

代码语言:javascript
复制
<?php
echo "hi"
?>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-23 12:17:46

测试id选择器错误,请在下面尝试

代码语言:javascript
复制
<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
EN

Stack Overflow用户

发布于 2011-07-23 12:18:55

:你的脚本中有很多缺陷。

代码语言:javascript
复制
The **$('Test').html(src);** will not work it should be **$('#Test').html(src);**

The **<?php>** should be just **<?php**
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6798179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档