AJAX/JQUERY-将返回的数据拆分并放置在两个单独的div中 [英] AJAX/JQUERY - Split the returned data and place in two seperate divs
本文介绍了AJAX/JQUERY-将返回的数据拆分并放置在两个单独的div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用以下代码每10秒运行一次AJAX查询以填充<div id="datacontainer"></div>
I am currently using the following code to run an AJAX query every 10 seconds to populate <div id="datacontainer"></div>
setInterval(function(){
$.ajax({
url: "ajax.php",
type: "GET",
cache: false}
).done(function(html) {
$( '#datacontainer' ).html( html );});},10000
);
我现在已经设置了ajax.php文件以返回一个字符串,该字符串现在包含我要拆分并填充两个div的定界符'----'.
I have now setup the ajax.php file to return a string that now contains the delimiter '----' that I want to split and populate two div's.
我想在拆分data[0]
进入<div id="nummessages"></div>
而data[1]
进入<div id="datacontainer"></div>
I want to split into data[]
when split data[0]
goes into <div id="nummessages"></div>
and data[1]
goes to <div id="datacontainer"></div>
该代码需要如何修改才能实现?
How would this code need to be modified to achieve this?
推荐答案
setInterval(function(){
$.ajax({
url: "ajax.php",
type: "GET",
cache: false}
).done(function(html) {
var divs = html.split('----');
$( '#nummessages' ).html( divs[0] );
$( '#datacontainer' ).html( divs[1] );
});
},10000);
这篇关于AJAX/JQUERY-将返回的数据拆分并放置在两个单独的div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文