Reputation: 24112
I have a JavaScript function that sends data to my PHP script via $.ajax
. My PHP script returns a number of things that I use to create a Jquery UI dialog box, such as the title of the box and its contents (html).
I am returning the bits of data (such as the dialog title and body) in one long string, with each segment separated by ::
, then using:
myStuff = data.split('::') ;
Finally, I use myStuff[n]
for the first part I want to use.
I would like to know if you guys know a better way of doing this? Better as in faster/less code, more secure etc.
Upvotes: 1
Views: 101
Reputation: 17930
Your best option is Json.
PHP has 2 great functions for dealing with Json, json_decode and json_encode
Upvotes: 5
Reputation: 104178
I believe that using a JSON object would be more appropriate. It would make the code more readable and would avoid the parsing, as Javascript can natively parse JSON objects:
var title = myObj.title;
There are many choices for creating JSON objects in PHP to chose from.
Upvotes: 4