Monday 15 August 2011

php - Not able to retrieve $_POST values through ajax call -


I have a problem with Ajax. This is my code that I have done so far:

 < Code> & lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; $ (Document) .ready (function () {getLocation ();}); Function getLocation () {if (navigator.jolocation) {navigator.geolocation.getCurrentPosition (showPosition); } And {warnings ("Geolocation is not supported by this browser."); }} Show show position (position) {latitude = position.coords.latitude; Longitude = position Calls. Lame; $ .post ({url: 'test.php', data: ({lat: latitude, long: longitude}), success: function (data) {warning ('done');}}); }   

What I am trying to do is to call the function on the document and to get the value of the AJAX call on the same file Trying to get the script where I had called it Whenever I reload the page, I do not get any value:

  print_r ($ _ POST ['lat']);   

I do not know what the real problem is, I have already checked in the console and I have not found any errors. help please.

You need to successfully print callback to get the price

  $ Post ({url: 'test.php', data: ({lat: latitude, long: longitude}), success: function (data) {warning (data);}});   

and if you enter

  if (isset ($ _ POST ['lat']) {print_r ($ _ POST ['lat' ];}   

You will find a value in the warning box.

Edit : If reqest comes from Ajax using this, PHP can check in:

  if ($ _SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {if (isset ($ _ POST ['lat']) {print_r ($ _ POST ['lat']);} Exit ();}   

If you keep it at the beginning, then you will see only print_r with a Ajax call.

No comments:

Post a Comment