By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

AJAX can't access php from outside xampp folder

P: 8
I wrote simple html file that use ajax to get response from a php file.

The php file is simply echo a string.

if the html file and the php is placed inside c:/xampp/htdocs and everything work well.

What i want is to place the html on the desktop and call the php file, it does not return anything.

i guess it is an apache, xampp confguration, can someone help me plz???
Apr 30 '12 #1
Share this Question
Share on Google+
13 Replies

Expert Mod 10K+
P: 12,369
And why can't you put it in htdocs?
Apr 30 '12 #2

P: 8
I can, and i tried it and succeed.
But when i place the html for example on the desktop or any folder outside the htdocs, ajax does not succeed in returning a response.
So it is a PHP, Apache or browswer problem? And how it can be solved.
Thank you
May 1 '12 #3

Expert Mod 10K+
P: 12,369
Why would you need to solve it? Just put it in htdocs.
May 1 '12 #4

P: 8
i need to call it from another computer or from a phone
May 1 '12 #5

Expert Mod 10K+
P: 12,369
Call what? Call a PHP file? You put the file in htdocs and then call it from where ever you want.
May 1 '12 #6

P: 8
Hey Rabbit, if you don't know the answer plz don't post a reply.
I repeat: i have an html file, that will be placed outside the htdocs folder, and inside the html an ajax functionality that call a php file inside the htdocs.

When i run the html it does not return anything.

The answer was:
you should put in ur php the following line;
header('Access-Control-Allow-Origin: *');

so again, don't post rabishh answerssss
May 1 '12 #7

Expert Mod 10K+
P: 12,369
It's not that I don't know about Access-Control-Allow-Origin. It's that I was trying to point out to you that there's no need to complicate things by doing that. If you are already serving the PHP file from your server, then just serve up the HTML file as well.

There's no need to activate cross domain access. By activating cross domain access, you now give everyone access to run your PHP code from anywhere they want. Cross domain access also opens up your server to more attack vectors, reducing your overall security.

So before you accuse someone of not knowing an answer and accuse them of posting rubbish, you should do your research.
May 1 '12 #8

P: 8
You was repating the same question and i answered many times that this is a scenario.

so what is your solution if not Access-Control-Allow-Origin?

In fact, i need to use html5 mobile application that retrieve data posted on the server. I have a backend that publish for example messages, i need the mobile application (html5) to retrive that data which is normally saved in db.

What do you think is the best solution for this?
May 1 '12 #9

Expert Mod 10K+
P: 12,369
I kept asking the same question because you never answered the question. You kept asking, in essence, how to allow for cross domain scripting. And I was asking, in essence, why do you need to allow for cross domain scripting? The answer, as far as I can tell, is you don't need cross domain scripting at all.

The way to do this is, have your HTML 5 page and your PHP page in your htdocs. When the user wants to access your data, they type in the URL for your web server, which will serve them the HTML 5 page which will retrieve data from the PHP page. There's no need to store an individual copy of the HTML 5 page on the device that is going to access the the PHP page.
May 1 '12 #10

P: 8
But, i need the application to be updated by the news without refreshing the page.
why not having a standalone application using phonegapp platform that will updated from the server just like facebook phone application.
I hope you got my point of view
May 1 '12 #11

Expert Mod 10K+
P: 12,369
Refreshing the HTML page? You don't need to refresh it. You just need to load it once and then use AJAX to refresh the section you want. That's what AJAX is for, to refresh only a part of a page without refreshing the whole page.
May 1 '12 #12

P: 8
I know rabbit, let me explain.
In reality all this was a testing, our purpose is to have a standalone
application for mobile (using html5 and phonegapp for crossplatform purposes) and this application gonna be updated by news posted from the server.
What is the best method to make this scenario?
May 2 '12 #13

Expert Mod 10K+
P: 12,369
Well, according to the phonegap website,
Q. I want to create an application for phonegap to access externally deployed web services via AJAX. How can i resolve the issue with the cross-domain security policy of XmlHttpRequest?

A. The cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply.

(in Android,you may grant android.permission.INTERNET to your app by edit the AndroidManifest.xml)
May 2 '12 #14

Post your reply

Sign in to post your reply or Sign up for a free account.