I'm using xampp on my Windows 10 dev machine and when I launch my javascript app using chrome, the browser uses localhost:8080 as the root directory.
For my php ajax calls, I have to use the fully qualified path to get them to work. For example:
$.ajax({
type: "GET",
dataType: "json",
url: "http://localhost/get_user.php",
data: {email: $("#email").val()}
});
Note that I have to use localhost for the ajax calls whereas the javascript root is localhost:8080. My php files are stored locally in c:/xampp/htdocs.
I want to use a short form url that works on both my local dev machine and on the production website. Something like
$.ajax({
type: "GET",
dataType: "json",
url: "/get_user.php",
data: {email: $("#email").val()}
});
My understanding (and I'm new to this) is that if I use the short form url /get_user.php the system uses the same root as the client side app (i.e. http://localhost:8080/get_user.php). But only fully qualified http://localhost/get_user.php is working for my ajax calls.
I get the following error message when using the short form /get_user.php:
GET
http://localhost:8080/check_login.php?password=xxxxxxxxxx&email=drew%40aol.com
404 (Not Found)
So the client side uses localhost:8080 and the server side expects localhost. I'm sure this is probably an xampp config issue but haven't been able to solve on my own. Any insight would be appreciated.
Try changing your data type to jsonp rather than json. I think you are running into a cross-origin resource sharing problem. A permission problem, essentially. localhost and localhost:8080 are two different domains, as far as your browser is concerned. If your code is executed from localhost:8080 and you give it a relative url, like /something.php, it assumes you are requesting it from the same domain. localhost is equivalent to localhost:80.
Related
I am trying a simple chat application using websocket. For that i have taken the coding from https://github.com/kishor10d/CodeIgniter-Ratchet-Websocket.
But i have found the below issue:
Source map error: request failed with status 404
Resource URL: http://localhost/ratchat/assets/js/angular.min.js
Source Map URL: angular.min.js.map[Learn More]
Source map error: request failed with status 404
Resource URL: http://localhost/ratchat/assets/js/angular-route.min.js
Source Map URL: angular-route.min.js.map[Learn More]
Firefox can’t establish a connection to the server at ws://192.0.53.1:8000/.(192.0.53.1:8000/.:this is my IP).
i had tried on terminal by giving :
php -q /var/www/html/chat/application/third_party/Realtime/bin/server.php
but not working
Any help
First run the server.php on Your console .Then it will works. I had try it anf works fine for me
I have a site which is using Basic Authentication, visitor can login with predefined credentials. I can reach the $_SERVER["PHP_AUTH_USER"] variable, so everything works fine here.
But when I'm trying to post data with jQuery AJAX in the same domain, I can't reach the $_SERVER["PHP_AUTH_USER"] variable (not set in the $_SERVER).
Environment:
Server version: Apache/2.4.7 (Ubuntu)
PHP Version: 5.5.9-1
Ubuntu: 4.9
(Server API: Apache 2.0 Handler, so not CGI)
Chromium: 41.0.2272.76
Ubuntu 14.04 (64-bit)
Can anyone help with this problem?
Along with greet, commented that the server will accept your application if you send in the request authentication, therefore you within Jquery Ajax method, and define Dentrol method the Autentification property through getAllResponseHeaders () function, an important point is in basic mode of authentication uses javascript base 64 (btoa) to encrypt the username and pass, I hope you find it useful and invite you to visit my github, enter link description here, have some useful ools Built to to validate data when luck
$.ajax({
url : 'test_2.php',
type : 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Basic ZWxlbWVudG86ZWxlbWVudG8=');
},
data: {},
success: function (e) {
console.log(e)
},
error: function (e) {
console.log(e)
},
});
I've got a very basic one today! I'm trying to post from jQuery to a PHP file hosted on localhost.
My JS:
$("#searchNameButton").click(function() {
var name = $("#searchNameText").val();
$.ajax({
type: 'POST',
url: 'localhost:8080/getNameInfo.php', // -> this works fine from the browser
// data: { name: name }, -> commented out
success: function(){
alert('request successful');
},
error: function(xhr, textStatus, errorThrown){
alert('request failed');
}
})
});
My PHP file (getNameInfo.php), a very basic one for testing:
<?php
echo 'TEST';
?>
In jQuery, it will always bring me to error, saying 'Internal Server Error'.
I am using Ripple Emulator and this is what appears in the console:
POST https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=localhost%3A8080/getNameInfo.php
500 (Internal Server Error)
I assume it has to do more with this than with what's written in the files. Any advice? Thanks!
EDIT: Found this: LINK but it won't fix my issue. If I do what it says here, I won't get any error thrown ("" instead) but will still fail.
EDIT 2: If I set Cross-Domain Proxy to Local in Ripple (that's suggested in the link above) I get
OPTIONS http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//localhost%3A8080/getNameInfo.php net::ERR_CONNECTION_REFUSED
EDIT 3: Changed my URL to local
C://Mobile//Cross-Platform//TestApp//www//php//getNameInfo.php
and it's working now. Have no idea how to make it work on localhost. BUt will go with this now, as it's only a learning app.
Add a header access control at top of getNameInfo.php file :
header('Access-Control-Allow-Origin: *');
So, finally I found a solution.
Even though it's not a recommended one, running Chrome with
--disable-web-security
will allow me to call a PHP script hosted on localhost:8080 from localhost:3000 where PhoneGap / Ripple Emulator stays.
I am building an Angular App with Gulp locally on my dev machine, that will eventually be a SaaS. All the data is hardcoded JSON in a service purely to get the front-end working.
Now I am ready to connect to a local database and will use PHP/MySQL.
I have a local development environment on OSX setup with Homebrew that has PHP and MySQL ready to go.
The issue:
I get a 404 when I use the url: 'db-insert.php' line no matter where I put the db-insert.php file in my directory structure.
POST http://localhost:3000/db-insert.php 404 (Not Found)
var request = $http({
method: 'post',
url: 'db-insert.php',
data: {
name: $scope.name,
email: $scope.email,
message: $scope.message
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
I have investigated
• CORS: Tried open -a 'Google Chrome' --args -allow-file-access-from-files
• gulp-connect-php
• gulp-webapp-running-browsersync-and-php
• BrowserSync Proxies
The app uses Gulps BrowserSync which has a proxy option that leverages Express to connect to a defined middleware, but I am stumped at where to point it or if it is the correct option at all.
Any explanation of what the correct way to do this is would be great. I think the answer is probably a combination of what I have found, but the implementation is the issue. Thanks much.
Ok, This turned out to be a filesystem/CORS issue. Here is how I solved it:
1) Go through the server to get to the php file
http://127.0.0.1/dev/db-insert.php
NOT
file://myproject/dev/db-insert.php
I was trying to access the file directly in the file system and not by its URL on the PHP server I have running as my localhost. When I changed the url to go through the apache server to find the file, it was able find it.
2) Once I got to the file I got the CORS issue
Adding the code below to the top of db-insert.php executes allowed the file to be accessed.The server could then execute the code.
header('Access-Control-Allow-Origin: '. $_SERVER['HTTP_ORIGIN'] );
header('Access-Control-Allow-Credentials: true' );
header('Access-Control-Request-Method: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: *,x-requested-with,Content-Type');
header('X-Frame-Options: DENY');
I have java classes that I call from my html file using this ajax code:
$.ajax({
type: "POST",
url:"http://www.verifiedalerts.appspot.com/verifiedalert?action=addIntrusionRules",
dataType:"text",
async:false,
data: "params=" + objStr,
success: function(data){
//alert(data);
}
});
when I see the log I get this error:
Uncaught exception from servlet java.security.AccessControlException: access denied
but when I run another similar file from a different computer it works somehow and now it is not working.
Does someone know how to get past this?
The error is occurring on the server, so we really need to see the App Engine code and the complete stacktrace of the exception to tell you anything useful. One thing that's immediately noticeable is that you're referring to "www.verifiedalerts.appspot.com" when you should probably be referring to "verifiedalerts.appspot.com" - the former may or may not work depending on your configuration.
I think it has to do with same origin policy:
The same origin policy prevents a
document or script loaded from one
origin from getting or setting
properties of a document from another
origin. This policy dates all the way
back to Netscape Navigator 2.0.
You might find these threads useful to workaround that:
Ways to circumvent the same-origin policy
Why same origin policy for XMLHttpRequest