网站跟域名是什么关系,城乡建设部网站 挂证,公益永久免费主机,电子商务网站建设公司我试图一些时间间隔后改变一个div的内部HTML。 我得到我想要使用Ajax正确的反应。 但无法取代内HTML的后#xff0c;并用Ajax响应地选择。 什么是错我的代码..HTML51 seconds ago58 seconds ago.....10 minute agoĴ查询setInterval(function() {$( .time ).each(…我试图一些时间间隔后改变一个div的内部HTML。 我得到我想要使用Ajax正确的反应。 但无法取代内HTML的后并用Ajax响应地选择。 什么是错我的代码..HTML 51 seconds ago 58 seconds ago..... 10 minute agoĴ查询setInterval(function() {$( .time ).each(function( index ) {var sendTime $(this).attr(data-time);dataString sendtimesendTimeqconvertTime;$.ajax({type: POST,url: data_handler.php,data: dataString,cache: true,success: function(response) {alert(response);$(this).html(response);//alert(response);}});});}, 5000);Answer 1:this是在回调的窗口。 使用给予的价值callback每个$( .time ).each(function(index , elem) {var sendTime $(this).attr(data-time);dataString sendtimesendTimeqconvertTime;$.ajax({type: POST,url: data_handler.php,data: dataString,cache: true,success: function(response) {alert(response);$(elem).html(response);}});});你并不需要定义一个新的变量来保护this在jQuery已经为您完成。Answer 2:当您使用的是异步函数的回调 this在你的回调并非来自同一背景。 您需要保存this在回调中使用的变量。尝试这样的setInterval(function() {$( .time ).each(function( index ) {var sendTime $(this).attr(data-time);dataString sendtimesendTimeqconvertTime;var self this;$.ajax({type: POST,url: data_handler.php,data: dataString,cache: true,success: function(response) {alert(response);$(self).html(response);//alert(response);}});});}, 5000);Answer 3:我认为$(这)是断章取义。 尝试setInterval(function() {$( .time ).each(function( index ) {var $this $(this);var sendTime $(this).attr(data-time);dataString sendtimesendTimeqconvertTime;$.ajax({type: POST,url: data_handler.php,data: dataString,cache: true,success: function(response) {alert(response);$this.html(response);//alert(response);}});});}, 5000);Answer 4:setInterval(function() {$( .time ).each(function( index ) {var sendTime $(this).attr(data-time);var _thisvariable $(this);dataString sendtimesendTimeqconvertTime;$.ajax({type: POST,url: data_handler.php,data: dataString,cache: true,success: function(response) {alert(response);_thisvariable.html(response);//alert(response);}});});}, 5000);文章来源: Replace inner HTML of a div with Ajax response