Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wordpress Ajax不工作?_Javascript_Jquery_Ajax_Wordpress - Fatal编程技术网

Javascript Wordpress Ajax不工作?

Javascript Wordpress Ajax不工作?,javascript,jquery,ajax,wordpress,Javascript,Jquery,Ajax,Wordpress,我正在wordpress中开发插件,我使用了select tag元素,我需要在更改选项值时将值存储在数据库中,但ajax似乎不起作用。下面是我的代码 这是脚本代码 函数ajaxFunction(str,id){ 所选var付款=str; var id=id; var queryString=“&id_take=“+id+”&sel=“+payment_selected; jQuery.ajax({ var data={'action':'my_action', “queryString”:que

我正在wordpress中开发插件,我使用了select tag元素,我需要在更改选项值时将值存储在数据库中,但ajax似乎不起作用。下面是我的代码

这是脚本代码
函数ajaxFunction(str,id){
所选var付款=str;
var id=id;
var queryString=“&id_take=“+id+”&sel=“+payment_selected;
jQuery.ajax({
var data={'action':'my_action',
“queryString”:queryString
};
post(ajaxurl、数据、函数(响应){
警报('从服务器获取此信息:'+响应);
});
});
}

您使用的
jQuery.ajax
似乎是错误的。尝试不使用
jQuery.ajax
包装代码,如下所示:

Javascript

function ajaxFunction(str,id) {   
    var data = {  
        'action' : 'my_action',
        'id_took': id,
        'sel'    : str
    };
    jQuery.post(ajaxurl, data, function(response) {
        alert('Got this from the server: ' + response);
    });
} 
HTML

<select  name='payment_select' id="payment_select" onchange="ajaxFunction(this.value,<?php echo $row->id ?>)">   
    <option value="Payment Due">Payment Due</option>
    <option value="Payment completed">Payment Completed</option>
</select>                       

你的控制台有什么错误吗?兄弟,我做了一些小改动,我现在就更新代码,请告诉我你不能像这样使用jQuery.ajax。检查那部分。请通读这篇文章,它会帮助你更多。是的,但它在select上返回0或1,但它正在我想要的数据库中更新,动态问题是“我的ajax不工作”,我回答了。要使您的查询有效,请提出另一个问题。因为它需要细节。
<?php

    add_action( 'wp_ajax_my_action', 'my_action' );

    function my_action() {

        global $wpdb;
        $id = $_POST['id_took'];
        $str = $_POST['sel'];
        $table_name_payment = $wpdb->prefix . "online_booking_system_model";
        if($whatever2=="Payment completed")
        {            
            $result_pay = $wpdb->query("UPDATE $table_name_payment SET 
            payment_status = $sel
            WHERE id = $id ");
            echo "success";            
        }       
    }
?>