Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Help needed for XML files.
Old 02-25-2008, 01:52 AM Help needed for XML files.
Extreme Talker

Posts: 163
Name: James
Location: Australia
Trades: 0
I am trying to use this fab dangle feature of Javascript, new XMLHttpRequest, and I need to know how to use it with a PHP file.

Could you explain, where in the below have I gone wrong?


I have used two test files for the XMLHttpRequest function to upload, being these
++ one with a .xml extention - This one works fine
++ one with a .php extention - I get an error message, dispite having the exact same text within the file.

The error happens,
As it tries to read,
xh=xml.getElementsByTagName("h")[a].childNodes[0].nodeValue;
Inside the onreadystatechange function.


While the PHP file is not on a PHP machine, it should read it just like Firefox treats such files as a normal HTML file, and while I have plain XML tags in the PHP file, it should treat that just like the .xml file.

I do have inside the function, the statement of xhr.responseText.contentType='text/xml';xml=xhr.responseXML;
TRANZIT JIM is offline
Reply With Quote
View Public Profile Visit TRANZIT JIM's homepage!
 
 
Register now for full access!
Old 02-25-2008, 04:37 AM Re: Help needed for XML files.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
While the PHP file is not on a PHP machine, it should read it just like Firefox treats such files as a normal HTML file, and while I have plain XML tags in the PHP file, it should treat that just like the .xml file.
Your problem lies in the mime type sent back by the browser.
.xml, is sent back as text/xml, .php is sent back as text/html.

You need to configure your server to serve .PHP as xml if you cannot use the PHP engine, or specify the mime type in php:
PHP Code:
//put this at the beginning of your php file
header('content-type: text/xml'); 
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-25-2008, 06:31 AM Re: Help needed for XML files.
Extreme Talker

Posts: 163
Name: James
Location: Australia
Trades: 0
The problem for me is, I am testing it here in my home PC first, before I put it onto the server.


How could I fix it for just this file only, to come out as text/xml when it is my own computer doing it.
TRANZIT JIM is offline
Reply With Quote
View Public Profile Visit TRANZIT JIM's homepage!
 
Old 02-25-2008, 06:43 AM Re: Help needed for XML files.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I'd say, you should install something like xampp http://www.apachefriends.org/en/xampp-windows.html, and you will be able to use PHP on your computer.

Otherwise, you must change the configuration of your web server, to explicitly tell it to serve the .php files as xml
http://httpd.apache.org/docs/2.2/mod...ml#AddEncoding
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-25-2008 at 06:45 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-27-2008, 01:20 AM Re: Help needed for XML files.
Extreme Talker

Posts: 163
Name: James
Location: Australia
Trades: 0
Quote:
Originally Posted by tripy View Post
I'd say, you should install something like xampp http://www.apachefriends.org/en/xampp-windows.html, and you will be able to use PHP on your computer.

Otherwise, you must change the configuration of your web server, to explicitly tell it to serve the .php files as xml
http://httpd.apache.org/docs/2.2/mod...ml#AddEncoding
I had just tired the above link, to put PHP on my computer, however, I kept on getting Windows alerts about some memory allocation error.

I had no choice but to 'un install' the product.
TRANZIT JIM is offline
Reply With Quote
View Public Profile Visit TRANZIT JIM's homepage!
 
Reply     « Reply to Help needed for XML files.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17233 seconds with 12 queries