Good day! I have this code in javascript

$.ajax({ type: "POST", url: "decklist.php", data: {data : jsonString}, cache: false, success: function(){ console.log("OK"); } }); 

and this code in php

 $data = json_decode(stripslashes($_POST['data'])); 

work in Google Chrome and Opera browsers, but do not work in Mozilla Firefox and the standard Android browser. Browser versions are quite new, no add-ons or plug-ins like ADBlock are worth it. Tried to change "POST" to "GET", but did not help. Tried to use different versions of jquery, also does not help! Javascript is generated using php in a wordpress plugin. decklist.php is in the same folder as it should be. Help me please! Thank you very much in advance!

    2 answers 2

    I checked the following code in firefox - everything works, did you happen to remember to do echo in a php script? jquery library which version? .. firefox which version? .... javascript is enabled in firefox? .. decklist.php is in the same folder as the html file?

      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> jsonString = '222'; alert('input_data=' + jsonString); $.ajax({ type: "POST", url: "decklist.php", data: {data : jsonString}, cache: false, success: function(data){ alert('Ok'); alert('output_data=' + data); } }); </script> 

    decklist.php code

     <?php $data = json_decode(stripslashes($_POST['data'])); echo $data; ?> 
    • There is an echo in the php script, a jquery library of the same version as in your code, the latest version of firefox, javascript is included, of course, decklist.php in the same folder. - ZeroBone

    With great difficulty I solved the problem by adding this:

     async:false, 

    in ajax request.

    • "With great difficulty" you have masked your problem, and sooner or later it will come out again. Imagine what it would be like if $.ajax really didn't work in Firefox! Yes, the Internet would just explode from screaming on this topic. Not to mention the fact that async: false deprecated in jQuery 1.8 - api.jquery.com/jQuery.ajax . - Igor