可能重复:
How to use split?
我正在尝试基于插件创建动态内容div。默认情况下,插件获取幻灯片对象并在逗号处将其分解。每个逗号后的每个字符串都是分开的。但是,当通过AJAX返回值时,它被解释为一个长字符串而不是被分解。如何让jQuery将其拆分为多个字符串?
Ajax:
$.ajax({
url: 'backend/index.php',
data: {'check':'true'},
type: 'POST',
async: false,
success: function(data) {
var carousel,
el,
i,
page,
slides = [ data ];
}
};
返回当前数据:
echo "
'<strong>Swipe</strong> to know more >>><br>Or scroll down for <em>Lorem Ipsum</em>',
'1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.',
'2. A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.',
'3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.'
";
exit();
幻灯片的默认示例:
slides = [
'<strong>Swipe</strong> to know more >>><br>Or scroll down for <em>Lorem Ipsum</em>',
'1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.',
'2. A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.',
'3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.'
];
作为参考,这是使用此处的SwipeView插件:http://cubiq.org/swipeview
答案 0 :(得分:1)
哦,伙计,这是一个糟糕的问题。提交后几分钟,我意识到它是多么容易。
编辑后端PHP返回:
$result = array('<strong>Swipe</strong> to know more >>><br>Or scroll down for <em>Lorem Ipsum</em>','1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.','2. A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.','3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.');
echo json_encode($result);
然后简单地添加到ajax:
dataType: "json",
感谢大家的帮助!