亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Wordpress ajax 請求無法正常工作

Wordpress ajax 請求無法正常工作

PHP
千巷貓影 2022-06-17 09:58:26
我是 wordpress 的新手,我在單擊按鈕上發出 ajax 請求并打印數據,但 ajax 沒有給我任何響應。請幫我找出錯誤。這是我的代碼add_action("wp_ajax_delivery_options", "delivery_options");add_action("wp_ajax_nopriv_delivery_options", "delivery_options");function delivery_options(){    echo json_encode(array('type' => 'success'));    wp_die();}wp_enqueue_script("my-ajax-handle", get_stylesheet_directory_uri() . "/js/custom.js", array('jquery'));wp_localize_script('my-ajax-handle', 'the_ajax_script', array('ajaxurl' => admin_url('admin-ajax.php')));阿賈克斯(function($) {  $(document).ready(function() {    $('#delivery_option button').on('click', function(e) {      e.preventDefault();      var data = e.currentTarget.id;      $.ajax({        type: 'POST',        dataType: 'json',        url: the_ajax_script.ajaxurl,        data: { delivery_option: data },        success: function(response) {          console.log(response);        }      });    });  });})(jQuery);任何解決方案表示贊賞!
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

你必須通過“回調函數名”data: { action: 'delivery_options', delivery_option: data },


(function($) {

$(document).ready(function() {

  $('#delivery_option button').on('click', function(e) {

    e.preventDefault();

    var data = e.currentTarget.id;

    $.ajax({

      type: 'POST',

      dataType: 'json',

      url: the_ajax_script.ajaxurl,

      data: { action: 'delivery_options', delivery_option: data },

      success: function(response) {

        console.log(response);

      }

    });

  });

});})(jQuery);


查看完整回答
反對 回復 2022-06-17
  • 1 回答
  • 0 關注
  • 78 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號