5 Replies - 392 Views - Last Post: 27 June 2012 - 04:11 PM Rate Topic: -----

#1 sonalmac  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 24-June 11

How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 01:14 PM

I have a script that fetches XML data through PHP (books.php). Another script, view.js with AJAX and Javascript is used to display the result from books.php. Now I want to send some data like book_id, author_id etc to next PHP script through either url or in a session. books.php simply echos out XML data in one string format, which then is manipulated in view.php.

   books.php

header('Cache-Control: no-cache');
header('Content-Type: text/xml');
//echo '<?xml version="1.0" encoding="utf-8" standalone="yes" 
  //<item>';

$stitle = $_GET['searchterm'];
$stitle = urlencode($stitle);
//echo $stitle;

$url = "books.xml?value1=" .$stitle;

$xml = file_get_contents($url);

echo $xml;

//If I manipulate xml file here, and get data into separate variables to send them to next php script, then it messes up javascript file view.js, which uses ajax to read the xml doc.




view.js uses ajax to read that xml document and print the data in web page. This data then I need to send to next php script.

Is This A Good Question/Topic? 0
  • +

Replies To: How to incorporate PHP, XML, AJAX and javascript

#2 mccabec123  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 214
  • Joined: 03-March 11

Re: How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 01:31 PM

Before we begin, AJAX is the incorporation of client-side and server-sde scripting to create a fluid experience for users, so that they do not have to change pages to send data to the server in question. Thus the reason why it is known as Asynchronous Javascript and XML.

Okay, now that we have that out of the way :P

I don't see what the problem is here, all you need to do is create a new form using javascript and set the action to the script that you need to send the data to, no?

This post has been edited by mccabec123: 27 June 2012 - 01:32 PM

Was This Post Helpful? 0
  • +
  • -

#3 sonalmac  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 24-June 11

Re: How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 01:43 PM

View Postmccabec123, on 27 June 2012 - 01:31 PM, said:

all you need to do is create a new form using javascript and set the action to the script that you need to send the data to, no?

Thanks mccabec123.

I mean my js script displays the data. I need to use this data to send to next script. Why (or how) to create a form?
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • Posts: 8,529
  • Joined: 08-August 08

Re: How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 02:45 PM

So then you need to set up your Javascript to either retain that information for when it calls the server again, or to make the data part of a form that will eventually submit a new request.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,524
  • Joined: 23-August 08

Re: How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 04:07 PM

Unless you have a compelling reason to use XML, the current standard for communicating between Javascript and a server is JSON.
Was This Post Helpful? 2
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3046
  • View blog
  • Posts: 4,562
  • Joined: 08-June 10

Re: How to incorporate PHP, XML, AJAX and javascript

Posted 27 June 2012 - 04:11 PM

Yea, I'd agree with JackOfAllTrades there. JSON is far easier to work with than XML, especially when you are using libraries like jQuery for the AJAX requests themselves.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1