Localhost - Ajax - call

I am loading data on a mouse-over-event. Do this via Ajax (jQuery) - like so:

	var city_id=element.id;
	var pfad="http://localhost/juwel/weltreise_get_city_status.php";
	var parameter={
		city_id	: city_id
		url	: pfad,
			data: parameter
			var dummy=response.split("|");
			if (dummy[0]=="OK") {
				var citystatus=document.getElementById("citystatus").
		.fail(function(xhr, status, errorThrown) {
			alert("Ajax Fehler.\nStatus="+status+"\nFehler="+errorThrown,"error");

Always get the error that the file was not found. Although it is definitely there. Wenn I call the "path" manually - everything works.

What am I missing here?

Probably a local file restriction or CORS. I use MAMP Pro for local development, and I can assign a hostname other than localhost. Maybe try using your local IP instead of localhost.

You are right - console says "CORS".

I am using MAMP Pro - but under "hosts" that "localhost" can't be changed ... anyway: I'll upload the files for testing - that works, although it is not very convenient.

Thanks for your help

Ah! Okay, in that case try:

header('Access-Control-Allow-Origin: *');

Make sure to remove that in production, though.


Geee - you are a real genius. Thanks - that works and saves a lot of time for developement.

1 Like