Wordpress admin-ajax.php 400 bad request

前端 未结 4 1119
無奈伤痛
無奈伤痛 2020-12-06 19:40

I have a strange and frustrating behaviour of wordpress admin-ajax.php file, when i make an ajax request it returns 400 error bad request.

(function( $ ) {
          


        
4条回答
  •  难免孤独
    2020-12-06 20:30

    First, use full and absolute url, with protocol (or at least protocol-independent form):

    var ajaxscript = { ajax_url : '//mydomain.com/wp-admin/admin-ajax.php' } 
    

    Second, your ajax action name is not the php callback function name but the dynamic part of the hook wp_ajax_{action_name} / wp_ajax_nopriv_{action_name}, so in your case it should be:

    data : {
        action : 'post_cart_clb',
        id : 1
    },
    

提交回复
热议问题