I am trying to Post and set some value on a PHP file called session.php using jQuery Ajax Post like

$("#up-data").on("click", function(){
        var data= { 
            url : 'www.google.com', 
            product : 'Map' 
        var request = $.ajax({
        type: "POST",
        url: ajax_set.ajaxurl,
        data: data,
        cache: false,
        crossDomain: true,
        beforeSend: function() {
         request.done(function( data) {

        request.fail(function( jqXHR, textStatus ) {
          console.log( "Request failed: " + textStatus );

looks like the POST is working fine here because I am not getting any error plus I am getting the Map www.google.com in the Response of fire bug and also in console for .done() without any error message

enter image description here

but in the session PHP

$u = $_POST["url"];
$p = $_POST["product"];
echo $u . "  " .$p ;

is returning nothing without any error message

enter image description here

Can you please let me know what I am missing or doing wrong and how I can fix this?


I'm having some doubts about your code. IF your using WordPress you should use https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

So you no session.php, but a function:

add_action( 'wp_ajax_foobar', 'my_ajax_foobar_handler' );

function my_ajax_foobar_handler() {
    $u = $_POST["url"];
    $p = $_POST["product"];
    echo $u . "  " .$p ;

and simplify yours JS

        'action': 'foobar',
        'url' : 'www.google.com', 
        'product' : 'Map' 
    function(response) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.