I made a basic ajax request to 2 variables. I want the values to be sent and manipulated in the back-end in order to use them in a database query. All that should happen on page load. My js code:

var lat =  21.458965;
var lng =  -11.336985;
jQuery.ajax({
        type:"POST",  
        url: ajaxurl,                   
        data: {'action':'func',
               'lat':lat,
               'lng':lng}, 
        success:function(data){
                // note that i don't want the data to return back to the front-end.     
                        },
                        error:function(errorThrown){
                            console.log(errorThrown);
                        }
                    });
        }

in the functions.php i created the func function:

function ppp(){
        if(isset($_REQUEST)){
        // i need to retrieve  both vars and take them out of the function then use them in a db query.
        }
    }

What i wanted here is to send data (2 int variables to be specific) from javascript file to functions.php so any other way to do that please tell me about it.

To do that i created a form with 2 hidden input elements using JS then submit it with $(‘form’).submit(); but the page was loading twice(the normal page load and the submit reload).

Read more here: Manipulate retrieved ajax data in php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: