• Hi i’m trying to use ajax in my theme but i get an empty alert after it runs.
    Here is my javascript code:

    var $e=jQuery.noConflict();
    $e(document).ready(function(){
    $e(“#formCarrito2”).submit(function() {
    var codigo = $e(“#formCarrito2 input[name=codice]”).val();
    $e.ajax({
    type: ‘POST’,
    url: ‘http://www.myurl.com/wp-admin/admin-ajax.php’,
    data: {
    action: ‘agregar_carro’,
    codigo: codigo,
    },
    success: function(data){
    window.location.href = “http://www.romigroup.it/pre-carrello”;
    $e(“.cantidad_confirm”).html(”);
    $e(“.cantidad_confirm”).append(data);
    },
    error: function(MLHttpRequest, textStatus, errorThrown){
    alert(errorThrown);
    }
    });
    });
    });

    And here my functions.php function.

    function agregar_carro(){
    //get data from our ajax() call
    $codigo = ‘<p>’.$_POST[‘codigo’].'</p>’;
    echo $codigo;
    die();
    }
    // create custom Ajax call for WordPress
    add_action( ‘wp_ajax_nopriv_myAjax’, ‘agregar_carro’ );
    add_action( ‘wp_ajax_myAjax’, ‘agregar_carro’ );

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Ajax empty alert’ is closed to new replies.