This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
request content on another domain/server
am trying to make an ajax request to a php code using xmlHTTPrequest, my application works on tomcat server, and am trying to make a request to PHP code in WAMP server (different server with request URL localhost), my PHP code simply receives a parameter,makes a query in a PostgreSQL database,and returns the result in XML format...my main problem is how to send the ajax request to that PHP code from my application that run on Tomcat with URL localhost:8080... any help will be appreciated, thanks
You should access the PHP script from within your application running on the tomcat server. Not from the client side.
check the following link.
adding header header('Access-Control-Allow-Origin: *');
to the PHP code might solve the problem
you can't make an ajax request to a different domain. that's not allowed for security reasons. if both of your servers run on the same domain though there's no problem using ajax to request information.
using an javascript API like jQuery will make this a lot easier. here's how to perform ajax requests with jQuery
Related
I am android developer and zero at back end process. Whats stuff/tools require for making a server/website that receives files from android app. I listen somewhere that php code is required as backend on server side. Is is true?
hoping for detailed explanation. Sorry for my english.
Thanks.
need php file for coonecting with database.use phpmyadmin(xampp)
tool for creating database.then create phpfile n post on server or localhost. after that use url in android.like our php link is localhost:80/phpproj/trial.php
and pass value to database using asyctask method.
This question already has answers here:
Origin is not allowed by Access-Control-Allow-Origin
(18 answers)
Closed 7 years ago.
I am developing a mobile application that uses js on the frontend and connects to a PHP backend which runs script against MongoDB database to return json data.Now everything was working fine as I tested the whole backend using localhost but now I want to upload the PHP files to some server so that I can test the whole thing using the actual mobile app.
So here's what I have done so far:-
I made my MongoDB database on MongoLab (they have a starter free plan) and I also uploaded my PHP files to google app engine (again for free). But now when I try to call a file using say Postman in google chrome, it shows Access-Allow-Control-Origin error, http://localhost is not allowed. I tried to google to find a solution to this but it didn't prove to be helpful as the error still persists.
So I switched to Amazon aws, fired up an ec2 instance, installed apache and PHP and uploaded my PHP files there, and I got the same Access-Allow-Control-Origin error.
So I guess my real question is can someone just walk me through the process of how I can upload my PHP files and have them connect to MongoDb database and then call them from localhost or from mobile app and have the result given to me.
P.S. - Sorry for such a long post but I just wanted to explain everything.
Add
header('Access-Control-Allow-Origin: http://localhost');
to the top of any page which has the problem.
This question already has answers here:
How to deny direct access to files in AJAX directory
(3 answers)
Closed 7 years ago.
I'm making an AJAX call from example.com/js/script.js to example.com/inc/ajax.php and need to deny direct access to the PHP file if a user tries accessing it directly via their browser.
The accepted answer here suggests checking a HTTP header. The problem with that approach is headers can be easily spoofed.
How can check if an AJAX-called PHP file has been accessed directly and provide a 403 Forbidden response?
Since each AJAX request is a normal browser request that happens in the background, it could be analyzed and reproduced with the developer-tools most browser provide.
The only thing i can think of is an one-time-token that you send with your ajax request that get validated and destroyed serverside. but even that could be tricked at some point.
I have a problem where the server I'm using is not configured to allow PHP or CGI and I need to send a mail using variables received from a form on this server to the owner, like a general enquiry/feedback form.
Does anyone know how I can call a simple PHP file on another domain configured to use PHP and then execute the mail() function on that server with variables passed to it from my non-PHP/CGI server?
How do I enable cross-domain AJAX calls without the originating server having PHP/CGI enabled?
Any feedback/advice would be greatly appreciated.
It's probably somehow doable using JSONP, but you don't need Javascript for this. The much easier solution would be to place the sending PHP script on the remote server, e.g.
www.serverwithphp.com/send.php
and then to point the feedback form directly to that script:
<form action="http://www.serverwithphp.com/send.php" ....>
and have send.php do a header redirect back to the original site after sending:
header("Location: http://www.serverwithoutphp.com/thanks.htm");
die();
On applications supporting it, you can do it with JSONP
I've got two servers running jsp and php. I'd like the PHP page to call the JSP page for getting an output. I tried using simple Ajax and Jquery-Ajax, it doesn't seem to work. Why?
you can't use ajax cross domains due to security restrictions. you could send the data to an php-script on your domain and send the post-request from there with a function like this
AJAX cannot request pages from sites that reside in different servers. This will make it a cross-side scripting attack. Hence, you have to go only through your server side code. For PHP you can use curl to get information from other pages. You can now use the same ajax script and link it to the php page containing curl. Documentation of curl can be found if you give a google over it.