Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 226 characters in body
Source Link
MEDZ
  • 149
  • 6

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 jsmain.js code:

main.js file

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:

functionwp_register_script( func'main', plugin_dir_url( __FILE__ ){
.'js/main.js', array( 'jquery' ) );
wp_enqueue_script( 'main' );

function func(){
    if(isset($_REQUEST)){
            //i tried to retrieve using $_POST and $_GET but the 2 arrays where empty.
            // i need to retrieve  both vars and take them out of the function then use them in a db query.
        
      
    }
  }
add_action('wp_ajax_func', 'func');
add_action('wp_ajax_nopriv_func', }'func');

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).

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 func(){
        if(isset($_REQUEST)){
        //i tried to retrieve using $_POST and $_GET but the 2 arrays where empty.
        // 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).

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 main.js code:

main.js file

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);
                        }
                    });
        }

functions.php

wp_register_script( 'main', plugin_dir_url( __FILE__ ).'js/main.js', array( 'jquery' ) );
wp_enqueue_script( 'main' );

function func(){
    if(isset($_REQUEST)){
            //i tried to retrieve using $_POST and $_GET but the 2 arrays where empty.
            // i need to retrieve  both vars and take them out of the function then use them in a db query.
             
    }
}
add_action('wp_ajax_func', 'func');
add_action('wp_ajax_nopriv_func', 'func');

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).

added 89 characters in body
Source Link
MEDZ
  • 149
  • 6

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 pppfunc(){
        if(isset($_REQUEST)){
        //i tried to retrieve using $_POST and $_GET but the 2 arrays where empty.
        // 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).

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).

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 func(){
        if(isset($_REQUEST)){
        //i tried to retrieve using $_POST and $_GET but the 2 arrays where empty.
        // 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).

added 430 characters in body; edited tags
Source Link
MEDZ
  • 149
  • 6

I made a basic ajax request to 2 variables. I want the values to staybe sent and manipulated in the back-end in order to use them in a database query. myAll 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 now ??!!!
        
        }
    }

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).

I made a basic ajax request to 2 variables. I want the values to stay in the back-end to use them in a database query. 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 now ??!!!
        
        }
    }

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).

Source Link
MEDZ
  • 149
  • 6
Loading