weixin_33671935 2015-03-24 21:39 采纳率: 0%
浏览 64

jQuery .post不发送数据

I am using the Wordpress heartbeat and am attempting to pass some data to my site using Ajax. I am able to see the action in my $_POST but my data is not available. The below .post is able to send a request to MyZabbix, that post contains my action, my action then works. However, I need access to the indexs['hosted']. Why would the below .post not send my data when sending the action?

     $( document ).on( 'heartbeat-tick', function( e, data ) {
         $.each( data, function( index, value ) {
             $.each( value, function( indexs, values ) {
                 var hostids = indexs['hostid'];
                 $.post( MyZabbix.ajaxurl, {
                     action:'zabbix_ajax_submit',
                     data: indexs['hostid']  },
                     function( api_response ) {
                         console.log( "Data Saved: " + api_response );
                 });
}(jQuery));
  • 写回答

1条回答 默认 最新

  • weixin_33674437 2015-03-25 22:11
    关注

    I decided to use the when function with my ajax request. The issue that I was experiencing was - My ajax request didn't always finish before the rest of my code executed. By moving my code into a function that executed only AFTER my ajax request was successful, I was then able to get every thing to behave as expected.

     var promise = $.ajax({
          type: "POST",
          url: MyZabbix.ajaxurl,
          async: true,
          data: { action:'zabbix_ajax_submit', data:value}
     });
     $.when(promise).done( successFunction );
    

    The when function is located in the documentation.

    The done function is located in the documentation.

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码