Do I need request headers with AJAX?

I am new to the whole javascript / jquery / ajax scene. I have a website that I developed on my personal machine using the following jquery ajax script. It works fine on my machine, but then when I upload it to the server, nothing happens.

$.post( "action URL here", { lat_max: params.lat_max, lat_min: params.lat_min, lng_max: params.lng_max, lng_min: params.lng_min, building_residents: params.building_residents, building_type: params.building_type }, function(json) { buildings = json; updateMarkers(); if(polygons.length > 0){ for(var i = 0; i < poly_buildings.length; i++){ buildPolyBuildings(); } }else{ showAllMarkers(); } filterResults(); }, "json" ); 

I have been banging my head about this for several hours, and the only idea I left concerns what I do not understand is the request / response headers. When I run this script on my live site, there is nothing in the request / response header in Firebug. However, there are many things when I run it locally. What am I not getting?


There was a request to see the difference in the headings. Here is what I get on my development server:

 ResponseHeaders Date Tue, 20 Dec 2011 20:45:07 GMT X-Powered-By PHP/5.3.6 Transfer-Encoding chunked Connection Keep-Alive Server Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 Content-Type text/html Keep-Alive timeout=5, max=100 RequestHeaders Content-Type application/x-www-form-urlencoded Accept application/json, text/javascript, */*; q=0.01 X-Requested-With XMLHttpRequest 

And here is what I can get on the server:

 ResponseHeaders RequestHeaders Content-Type application/x-www-form-urlencoded Accept application/json, text/javascript, */*; q=0.01 

Again - I do not know that this is a problem, but this is the only functional difference that I see between the two environments.

+4
source share
2 answers

I understood what was going on. It turns out that in the domain in which I was going, there was no "www" in front of him - I was going to the bare domain. And the URL that it refers to in the code has the www subdomain in front of it. He decided everything. Thank you for your help!

+1
source

Do you have access to error logs on the new server? I recently ran into a problem similar to yours, and it turned out that php on the new server was configured differently than the version on the old server, that is, the page that I got through AJAX failed (and did not send a response). This may cause your problem.

+1
source

Source: https://habr.com/ru/post/1387175/


All Articles