Hi,
I'm somewhat new to jQuery/JavaScript, so any help would be greatly appreciated.
I have a few textboxes that need to be populated when a user clicks a hot spot on an image map. Each hot spot has an alt tag representing the ID number of the object I need to retrieve from a database.
To retrieve the info from the DB, I have a small PHP script that is called with jQuery's .post() function, something to the effect of:

$.post($('#myForm').attr('action'),formInput, function(data){ ... });

My question is how do I use jQuery to get and manipulate the data that the PHP function retrieves from the DB?

Thanks in advance for any assistance.
- EF

I understand that I can use success: function(html) { $('#response').html(html); to print any code that was echo'ed by the php script. But what I want to do is return an array from the script and manipulate it to output its contents in specific places. How could I do that?

hmmm. okay you just have to use your imagination.

first, there is a split function in JS: that is http://stackoverflow.com/questions/2049033/how-to-split-string-using-jquery

so, you can just put delimiter on the echo'd data coming from the PHP script.

for example

var str = html; //assuming the data is hello||john||world
var arr = str.split("");
//now doing this will give you 3 separate data
document.write(arr[0]);
document.write(arr[1]);
document.write(arr[2]);

Hope this helps
Cheers!

commented: Good idea for how to solve my problem. +2

Thanks, this is the idea that was starting to form in my head. I originally wanted to return an associative array because it would be easier for me to manipulate, but I think I'll just echo a string with a delimiter and split() it. Glad to see I was headed in the right direction. Thanks!

oh! I've forgotten!!

the function should be

var arr = str.split("||");
not var arr = str.split("");

btw it's impossible to retrieve an Array Variable from a PHP script to JQuery AJAX. it is always a raw data.

Cheers! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.