可能重复:
如何使用拆分?
我正在尝试基于插件创建一个动态内容 div。默认情况下,插件采用幻灯片对象并以逗号分隔它。每个逗号后面的每个字符串都是分隔的。但是,当通过 AJAX 返回一个值时,它被解释为一个长字符串,而不是被分解。如何让 jQuery 将其拆分为多个字符串?
阿贾克斯:
$.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