0

Possible Duplicate:
How to use split?

I'm trying to create a dynamic content div based off of a plugin. By default, the plugin takes the slides object and breaks it up at the commas. Each string after every comma is separated. However, when returning a value via AJAX, it is being interpreted as one long string instead of being broken up. How can I get jQuery to split it into multiple strings?

The Ajax:

$.ajax({
url: 'backend/index.php',
data: {'check':'true'},
type: 'POST',
async: false,
success: function(data) {
    var carousel,
    el,
    i,
    page,
    slides = [ data ];
}
};

The current data being returned:

echo "
    '<strong>Swipe</strong> to know more &gt;&gt;&gt;<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();

The default example for slides:

slides = [
    '<strong>Swipe</strong> to know more &gt;&gt;&gt;<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.'
];

For reference, this is using the SwipeView plugin found here: http://cubiq.org/swipeview

Community
  • 1
  • 1
aaronhuisinga
  • 299
  • 1
  • 5
  • 16

1 Answers1

1

Oh man, this was a bad question. Minutes after submitting it I realized how easy it was.

Edited the backend PHP to return:

$result = array('<strong>Swipe</strong> to know more &gt;&gt;&gt;<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);

Then simply added to the ajax:

dataType: "json",

Thanks for the help everyone!

aaronhuisinga
  • 299
  • 1
  • 5
  • 16