【问题标题】:Copy Ajax request function, that calls a php function, noob stuff复制 Ajax 请求函数,调用 php 函数,菜鸟的东西
【发布时间】:2012-11-07 10:36:51
【问题描述】:

我找到了一个 JS-Jquery 文件,它几乎可以满足我的需要。如果您单击复选框,它会调用一个 php 函数。现在我想添加另一个复选框来调用另一个 php 函数。

所以我尝试复制该功能。并更改值,但这不起作用。

我相信您会在 1-2 秒内看到错误,因此感谢您在 JS-Fiddle 中的简短查看!

这部分我想复制,也可以看看我在 JS-Fiddle 中的尝试

$('input[name="ive-read-this"]').change(function (evt) {
    alert("markiere als gelesen.");

    // We can retrieve the ID of this post from the <article>'s ID. 
    // This will be required
    // so that we can mark that the user has read this particular post and 
    // we can hide it.
    var sArticleId, iPostId;

    // Get the article ID and split it - the second index is always 
    // the post ID in twentyeleven
    sArticleId = $("article").attr('id');
    iPostId = parseInt(sArticleId.split('-')[1]);

    // Initial the request to mark this this particular post as read
    $.post(ajaxurl, {        
        action:  'mark_as_read',
        post_id: iPostId      
    }

【问题讨论】:

  • 张贴你复制的代码..你得到错误的地方..不是正在工作的那个..:) :)
  • 修复小提琴中的语法错误。
  • @bipen 不工作的是 JS-Fiddle。
  • @mickylaaaad 已修复,效果更好,但我在标记为未读时收到错误消息
  • 使用一些调试工具来确定问题出在哪里。例如,前端可以使用 Chrome 的开发工具或 Firebug,后端可以使用 Xdebug。

标签: php javascript jquery ajax wordpress


【解决方案1】:

我只是忘了添加这个:

add_action('wp_ajax_mark_as_unread', 数组(&$this, 'mark_as_unread'));

这样就解决了! 问候

【讨论】:

    猜你喜欢
    • 2017-01-11
    • 2013-07-03
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 2011-10-24
    相关资源
    最近更新 更多