Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
Php jquery在单击specfic div时获取数据,我希望在单击ajax1时获取数据_Php_Jquery_Ajax - Fatal编程技术网

Php jquery在单击specfic div时获取数据,我希望在单击ajax1时获取数据

Php jquery在单击specfic div时获取数据,我希望在单击ajax1时获取数据,php,jquery,ajax,Php,Jquery,Ajax,我希望当我们点击ajax1时,ajax1的内容会发生变化,但AJAX2将保持不变,反之,我希望通过jquery实现这一点 <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#pas").click(fun

我希望当我们点击ajax1时,ajax1的内容会发生变化,但AJAX2将保持不变,反之,我希望通过jquery实现这一点

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#pas").click(function(){
  $.ajax({url:"001.php?q=1 & l=111", success:function(result){
    $("#pas").html(result);
  }});
});});
</script>
</head>
<body>
<div id="pas"><h2>AJAX 1</h2></div>
<div id="pas"><h2> AJAX2 </h2></div>
</body>
</html>

两个元素不能具有相同的id。应更改为使用类

<div class="pas"><h2>AJAX 1</h2></div>
<div class="pas"><h2> AJAX2 </h2></div>

您必须区分div的id:为它们提供两个不同的id,即pas1和pas2以及相同的类“pas”,然后在div.pas上启动操作。不要使用重复的id,而是使用类。使用对单击对象的参照来更新内容。这是您修改过的代码:

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").click(function(){
  var _this = this;
  $.ajax({url:"001.php?q=1 & l=111", success:function(result){
    $(_this).html(result);
  }});
});});
</script>
</head>
<body>
<div><h2>AJAX 1</h2></div>
<div><h2> AJAX2 </h2></div>
</body>
</html>

查找jQuery上下文属性。。在url属性中,放置“contect:this”,然后在调用success函数时,它将引用单击的div:我对需要发生什么感到非常困惑?您的意思是,当您单击某个元素以启动AJAX请求时,您只希望更新该特定元素的内容,或者至少更新该元素的一个子元素,而不希望更新其他内容?请再澄清一点。谢谢。你怎么能指望这两个元素的ID都是一样的呢?废话,刚刚删除了我的答案,你比我快了几秒钟,詹姆斯+1.如果我获得了关于主题的评论,并且评论是从div id=pas中的数据库中获得的,我希望当用户单击第12条评论,然后在第12条显示结果时,这个divok frz我获得了从数据库内容中获取的所有div,如果我获得了关于主题的注释,我如何自动生成idfriends,评论来自div id=pas中的数据库,我希望当用户点击第12条评论,然后在这个div上显示结果时,我会尝试这个,当我有空时,但如果我删除div类,我会问你另一个问题,当用户单击div时,内容将发生变化当我单击ajax 1时,内容将被删除,且无法获取内容请告诉mesir它包含简单的html文本如果我删除div的id,当用户单击div内容时,内容将发生变化code.jquery.com/jquery latest.js>$document.readyfunction{$pas.clickfunction{$.ajax{url:001.php?q=1&l=111,成功:functionresult{$pas.htmlresult;};};};ajax1 AJAX2
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").click(function(){
  var _this = this;
  $.ajax({url:"001.php?q=1 & l=111", success:function(result){
    $(_this).html(result);
  }});
});});
</script>
</head>
<body>
<div><h2>AJAX 1</h2></div>
<div><h2> AJAX2 </h2></div>
</body>
</html>