AJAX request from Chrome Extension to Wordpress Website
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: "https://www.groupio.fr/wp-admin/admin-ajax.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 !