Ajax Works in Firefox but not in Chrome

456
December 10, 2016, at 1:22 PM

Everything works well in firefox, all the data return a value, but on chrome, they are all undefined. I tried to empty my function with only a simple string return ex. 'asd' and this still return Undefined. Working on wordpress.

$('.vote-synergy-up, .vote-synergy-down').click(function(){
    var data_synergy = $(this).parent('.vote-synergy-container').attr('data-synergy'); /*PK SYNERGY*/
    var VoteType = '';
    var OtherVoteType = '';
    if ($(this).hasClass('vote-synergy-up')){
        VoteType = 'Up';
        OtherVoteType = 'Down';
    }
    if ($(this).hasClass('vote-synergy-down')){
        VoteType = 'Down';
        OtherVoteType = 'Up';
    }
    // This does the ajax request
    $.ajax({
        type: "POST",
        url: omvp_ajax.ajax_url,
        dataType: 'json',
        data: {
            'action':'synergy_vote',
            'pk_Synergy' : data_synergy,
            'VoteType' : VoteType
        },
        success:function(data) {
            alert(data.Test)
        },
        error: function(errorThrown){
            alert('An error as occured');
            console.log(errorThrown);
        }
    });  
});

Here is my function

function synergy_vote() {
if ( isset($_REQUEST) ) {
    echo json_encode(
        array(
            'Test'=>'ASD'
            )
    );
}

}

Answer 1

Try parsing the JSON that's returned from the server.

success:function(data) {
    var d = $.parseJSON(data);
    alert(d.Test);
},
Answer 2

Replaced

add_action( 'wp_ajax_synergy_vote', 'synergy_vote' ); // It called from the back end

With

add_action( 'wp_ajax_nopriv_synergy_vote', 'synergy_vote' );    // If called from front end
Rent Charter Buses Company
READ ALSO
conflict between multiple js files in wordpress install?

conflict between multiple js files in wordpress install?

Im really clueless on thisIm working on a Wordpress site for a friend and he gave me a free theme to use

340
jQuery animate.css not working correctly on Firefox only

jQuery animate.css not working correctly on Firefox only

I'm pretty much a novice at jQuery and i'm trying to use some animations which work fine except on Firefox

459
Javascript move text between brackets in textarea

Javascript move text between brackets in textarea

I have a simple text area with text like this:

382