0

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

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by MooGeek
0

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?

1

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!

Votes + Comments
Good idea for how to solve my problem.
0

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!

0

oh! I've forgotten!!

the function should be

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

0

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

Cheers! :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.