Jump to content

WordPress AJAX. jQuery Post data not available


Recommended Posts

Hello everyone!

I've been at this WordPress AJAX functionality for almost 2 weeks and I've had it working in a basic state for about 2 days. However passing along geolocation data WITH the $.ajax data is ruining my life. Here's what's going on:


// click "trigger" function

  // data: object
  data = {
     latitude: $('input#latitude').attr('value'),
     longitude: $('input#longitude').attr('value')
}); // end click func
    function _do_ajax(obj) {
            url: My_Obj.ajaxurl, // the request is sent to admin-ajax.php
            data: data,
            dataType: 'json',
            success: function( response ){ loops and stuff }

WordPress is very specific as to the ways you can do AJAX requests. If you're not familiar with them: The above queries a wp_ajax_ACTION in functions.php. My action function is called wpa56343_search. This function is where I need to include post variables for use within the query it performs.


The way it is working now logs 

Object {action: "wpa56343_search", latitude: "42.041261299999995", longitude: "-70.9414206"} 

Now why can't I get these through traditional methods such as:

$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
// to use within the query function
function my_ajax_search($latitude, $longitude){ query here }
Edited by BenRacicot
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.