How to write THIS jquery ajax code in PLAIN js to send to PHP?
I've been using jquery ajax all over my website to return data from PHP as json_encode(). And works fine in Firefox, but Chrome, Safari and mobile browsers make the users ajax requests like 10 times slower. I do receive a TON of JSON's coming from PHP back to my jquery success.
I've been trying to replicate this jquery ajax code to receive it in PHP as I receive it with jquery, as a $_POST superglobal for each JSON element.. I've tried a lot of different ways with plain JS but couldn't get it to work AT ALL. I hope I could get some help here. Thanks!
jquery ajax:
$.ajax({ dataType: 'JSON', data: { string_1:string_1, string_2:string_2 }, type: 'POST', url:url, success: function(data) { $('.div_1').html(data.string_1); $('.div_2').html(data.string_2); } });
PHP (I receive the above code as the following):
$string_1 = $_POST['string_1']; $string_2 = $_POST['string_2']; $json_arr = array( 'string_1'=>$string_1, 'string_2'=>$string_2 ); echo json_encode($json_arr);