gpt4 book ai didi

JavaScript 和 Ajax 响应

转载 作者:行者123 更新时间:2023-11-28 13:34:11 25 4
gpt4 key购买 nike

我有一个 javascript 文件,它应该与我的 ajax 请求的响应进行交互,但显然 javascript 无法读取 ajax 请求的响应。

我要问的是,如何让我的 jquery 插件读取我的 ajax 请求响应中的类?

这就是我的脚本在没有 ajax 的情况下的样子:

 <body>
<div id="main_content">

<!--this is where the ajax is returning the info-->
</div>
</body>

<body>
<div id="main_event_saff">

<!--this is an example of the ajax returns-->
<table>
<tbody>
<tr>
<td class="header">Header</td>
</tr>

<tr>
<td class="data">Data</td>
</tr>
</tbody>
</table>
</div>
</body>

Ajax 文件:

 $(document).ready( function rankings(callback){

$.ajax({

url: 'ajax/rankings.php',
type: 'GET',
success: function(response){

$('#main_event_saff').html(response);

}

});

});

这是我想要读取ajax请求响应的插件:

 $(document).ready(function () {
$(".data").hide();

$(".header").click(function () {
$(this).next(".data").slideToggle(200);
});

});

这不起作用,因为它无法读取ajax请求

就像它只能看到的页面源一样

最佳答案

正如你所说,你正在使用 jQuery,为什么不这样做

  $(document).ready( function rankings(callback){
$.ajax({
url : 'ajax/rankings.php',
type : 'GET',
data : 'yourData',
success : function(response){
$('#main_event_saff').html(response);
}

});
});

这将使您的工作变得轻松

关于JavaScript 和 Ajax 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22704368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com