Ajax适用于Firefox,但不适用于Chrome [英] Ajax Works in Firefox but not in Chrome
本文介绍了Ajax适用于Firefox,但不适用于Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图清空我的函数只有一个简单的字符串返回前。 'asd',这仍然返回未定义。
使用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 =' ';
OtherVoteType ='Down';
}
if($(this).hasClass('vote-synergy-down')){
VoteType ='Down';
OtherVoteType ='Up';
}
//这就是ajax请求
$ .ajax({
type: POST,
url:omvp_ajax.ajax_url,
dataType:'json',
data:{
'action':'synergy_vote',
'pk_Synergy' :data_synergy,
'VoteType':VoteType
},
成功:函数(数据){
aler t(data.Test)
},
错误:function(errorThrown){
alert('An error as occured');
console.log(errorThrown);
}
});
});
这是我的功能
$ b $ pre (
$ test $ >'ASD'
)
);
$ / code>
}
解决方案
替换
add_action('wp_ajax_synergy_vote','synergy_vote'); //从后端调用
用
add_action('wp_ajax_nopriv_synergy_vote','synergy_vote'); //如果从前端调用
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'
)
);
}
}
解决方案
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
这篇关于Ajax适用于Firefox,但不适用于Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文