Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 在使用wp_ajax进行调用时,我在Wordpress中遇到了一个400错误请求错误_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript 在使用wp_ajax进行调用时,我在Wordpress中遇到了一个400错误请求错误

Javascript 在使用wp_ajax进行调用时,我在Wordpress中遇到了一个400错误请求错误,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我在一个Wordpress项目中工作,我想通过ajax在我的网站上加载一些东西。我正在通过ajax加载许多节,但我以前从未遇到过错误。在这里,我也在做所有应该怎么做的事情,但我不知道为什么我会收到400个错误的请求。代码如下: if(!function_exists('enque_this')){ function enque_this(){ wp_enqueue_style( 'style-name', MY_PLUGIN_LOCATION.'css/style.css');

我在一个Wordpress项目中工作,我想通过ajax在我的网站上加载一些东西。我正在通过ajax加载许多节,但我以前从未遇到过错误。在这里,我也在做所有应该怎么做的事情,但我不知道为什么我会收到400个错误的请求。代码如下:

 if(!function_exists('enque_this')){
 function enque_this(){
    wp_enqueue_style( 'style-name', MY_PLUGIN_LOCATION.'css/style.css');
    wp_enqueue_script('my_script_file',MY_PLUGIN_LOCATION.'js/md-referral.js','jQuery','',true);
    wp_localize_script('my_script_file','ajax_object',array('ajax_url' => admin_url('admin-ajax.php'),'we_value'=>1234));
 }}
 add_action('wp_enqueue_scripts','enque_this');
   if(!function_exists('enque_single_prod_page')){
     function enque_single_prod_page(){
        wp_enqueue_script('my_script_file_2nd',MY_PLUGIN_LOCATION.'js/md-single.js','jQuery','',true);
        
     }}
      add_action('wp_enqueue_scripts','enque_single_prod_page');

function how_much_dis(){

        echo 'really .. . .!!! i Got SomeTHing ??';
};

add_action('wp_ajax_how_much_dis','how_much_dis');
jquery代码

jQuery(document).on("click","#submit_reff_code",function(){
    
    var codes = jQuery("#input_reff_code").val(); 
    var button_text = jQuery("#submit_reff_code").val("Please Wait . . .");
    var is_disabled = jQuery('[name="add-to-cart"]').prop('disabled');
    var product_id = jQuery('[name="add-to-cart"]').val();
    var variation_id = jQuery('[name="variation_id"]').val();


        if( codes != "" &&  codes.length > 2 && is_disabled == false && jQuery.isNumeric(product_id)){

            var data = {
                'action' :  'how_much_dis',
                'product_id_from_prod' : product_id,
                'variation_id_from_prod': variation_id,
                'code'       : codes
            };
            jQuery.post(ajax_object.ajax_url, data , function(response){
                
                    console.log(response);  

            });

        }else{
            alert("please enter valid code");
        };




});

感谢您的帮助,thanxx意味着行动是错误的。问题中的代码应该在用户登录时起作用。要在用户未登录时使其工作,必须添加行

add_action('wp_ajax_nopriv_how_mou dis'、'how_mou dis')


也许这就是原因。

400意味着行动是错误的。问题中的代码应该在用户登录时起作用。要在用户未登录时使其工作,必须添加行

add_action('wp_ajax_nopriv_how_mou dis'、'how_mou dis')


也许这就是原因。

是的,Thanx先生。当用户登录到thanxx以获得您的回复时,代码正在运行sirYes Sir Thanx。当用户登录您的回复时,代码正在运行