ajax

using php arrays in ajax

Page 1 of 1

4 Replies - 823 Views - Last Post: 07 August 2008 - 03:27 AM

#1 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

ajax

Posted 05 August 2008 - 12:59 AM

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..
Is This A Good Question/Topic? 0
  • +

Replies To: ajax

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: ajax

Posted 05 August 2008 - 03:54 PM

you can dynamically create Javascript with PHP..i'm not sure if it's what you mean, but you can do something like:
//JS function
function myfunction()
{
url = "<?php echo $url; ?>"
}

Was This Post Helpful? 0
  • +
  • -

#3 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: ajax

Posted 06 August 2008 - 04:01 AM

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: 06 August 2008 - 04:04 AM

Was This Post Helpful? 0
  • +
  • -

#4 mocker  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 50
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: ajax

Posted 06 August 2008 - 08:52 AM

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.ab...ry/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:
var xmlDoc = request.responseXML;
var priceArray = xmlDoc.getElementsByTagName('price');

Was This Post Helpful? 1
  • +
  • -

#5 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: ajax

Posted 07 August 2008 - 03:27 AM

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. B)

because i don't know xml...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1