Welcome to Dream.In.Code
Click Here
Getting Help is Easy!

Join 118,309 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,702 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



ajax

 
Reply to this topicStart new topic

ajax, using php arrays in ajax

kummu4help
post 5 Aug, 2008 - 12:59 AM
Post #1


D.I.C Head

Group Icon
Joined: 5 Aug, 2008
Posts: 122



Dream Kudos: 25
My Contributions


hi
i'm a new beee.. to ajax and also for forums..

here's my question goes...

i have a php array and i want to access that array in my ajax script...
how can i access the above mentioned php array in my script..
User is offlineProfile CardPM

Go to the top of the page


JBrace1990
post 5 Aug, 2008 - 03:54 PM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 458



Thanked 20 times

Dream Kudos: 350
My Contributions


you can dynamically create Javascript with PHP..i'm not sure if it's what you mean, but you can do something like:
php

//JS function
function myfunction()
{
url = "<?php echo $url; ?>"
}
User is offlineProfile CardPM

Go to the top of the page

kummu4help
post 6 Aug, 2008 - 04:01 AM
Post #3


D.I.C Head

Group Icon
Joined: 5 Aug, 2008
Posts: 122



Dream Kudos: 25
My Contributions


thanks jbrace..

but what i'm trying is i've a php script that will return an array(that holds database values)
i want to use that array in my ajax script ..
is there any way for that..
in short i'll call the php in ajax script and i've to catch that array and then
i have to fill the contents of array in textfields of my html page

This post has been edited by kummu4help: 6 Aug, 2008 - 04:04 AM
User is offlineProfile CardPM

Go to the top of the page

mocker
post 6 Aug, 2008 - 08:52 AM
Post #4


D.I.C Head

**
Joined: 14 Oct, 2007
Posts: 219



Thanked 11 times
My Contributions


You can't pass the actual variables from php running on the server to javascript running on the clients browser. What you can do, is have ajax request the php page, have php print the variables in some format (such as xml), and then have the javascript parse the xml and load it into its own arrays.

Javascript has very good support for parsing XML. From http://javascript.about.com/library/blajax12.htm
QUOTE
For example if we are exmecting a number of entries inside <price> </price> tags in the XML then we can extract them into a Javascript array using:
CODE

var xmlDoc = request.responseXML;
var priceArray = xmlDoc.getElementsByTagName('price');

User is offlineProfile CardPM

Go to the top of the page

kummu4help
post 7 Aug, 2008 - 03:27 AM
Post #5


D.I.C Head

Group Icon
Joined: 5 Aug, 2008
Posts: 122



Dream Kudos: 25
My Contributions


Thanks mocker for ur help....
today i saw the same solution in some website during my googling...
thanks again and can u point me to some good xml learning website. cool.gif

because i don't know xml...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/10/08 11:49AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month