admin管理员组文章数量:1404596
I developed a chrome extension which extract some data from the user visiting page and I want to transmit them to my database by an AJAX call (my website is a basic wordpress website).
The point is that the ajax response is error 400 and I do not understand where is the problem as I tried to modify my ajax request the best I could.
Here is my AJAX request from content.js
/* Popup clicked */
$('#myOwnCustomToolBar_TT91 #message_to_click form.groupio_form #subscribe').on('click', function(){
chrome.runtime.sendMessage(product_infos);
});
Here is the new background.js file :
chrome.runtime.onMessage.addListener(function(response, sender, sendResponse){
jQuery.ajax({
type:"POST",
url: ".php",
contentType: 'json',
dataType: "JSON",
responseType:'json',
data: {
action : "itempricingfunction",
ean : "EANTEST0101010"
},
success:function(data){
alert(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
Here is my function called itempricingfunction inside the functions.php file of my wordpress theme file
function itempricingfunction(){
$product_ean = (isset($_POST['ean'])) ? htmlentities($_POST['ean']) : NULL;
echo json_encode(array('product_ean' =>$product_ean));
exit;
}
add_action("wp_ajax_nopriv_itempricingfunction", "itempricingfunction");
add_action("wp_ajax_itempricingfunction", "itempricingfunction");
And finally, when I go to the product page and click on the chrome extension, the response of the ajax call is Error 400.
Thank you very much for your help !
本文标签: rest apiAJAX request from Chrome Extension to Wordpress Website
版权声明:本文标题:rest api - AJAX request from Chrome Extension to Wordpress Website 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744817526a2626787.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论