admin管理员组文章数量:1313176
I am trying to use ajax to pass value of the checklist to php in wordpress. I am using plugin to insert php on a page as a shortcode. Then inside the theme I created a js file with js/ajax code. I tested the console appearing on the checkbox click and it responds, but my ajax doesn't do what it supposed to do. This is my checkbox (HTML) inserted into the page with plugin:
<input type='checkbox' class='checkboxes' id='myID' name='myName' value='myValue'>
My script inside the theme
var $jq = jQuery.noConflict();
$jq(document).ready(function() {
$jq('.checkboxes').click(function() {
selected_checkbox= $jq(this).attr('id');
var checkBox = document.getElementById(selected_checkbox);
if (checkBox.checked == true){
var is_checked = "checked";
$jq.ajax({
type: "POST",
data:{
selected_checkbox: selected_checkbox,
is_checked: is_checked
}
});
}else{
var is_checked = "unchecked";
$jq.ajax({
type: "POST",
data:{
selected_checkbox: selected_checkbox,
is_checked: is_checked
}
});
}
});
});
And my php to call for the ajax result (again inserted on the page with a plugin)
if( $_POST['is_checked']=='checked' ){
$selected_checkbox=$_POST['selected_checkbox'];
echo $selected_checkbox;
exit;
}
Do I need URL set up (if so, what will the url be for the page 'localhost/myxeample/mycheckbox'? as this confuses me in wp)? Or since javascript works on the destination page ajax should pass the value too?
本文标签: javascriptHow to pass value from ajax to php in no conflict mode
版权声明:本文标题:javascript - How to pass value from ajax to php in no conflict mode? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741927995a2405405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论