dougang1605 2015-02-23 17:12
浏览 30
已采纳

Ajax调用DB保存仅在Wordpress中偶尔使用

I am creating a plugin and all functionality seems to work ok. However, in the admin page i am using an ajax call to a php file to save information entered into a form.

Sometimes it saves, other times it doesn't.

  1. THE FORM - call example

    form onsubmit="functionCall()" id="formSave"

  2. AJAX FUNCTION

     var url = 'http://localhost/';
    var link_id = '1';
    $.ajax({
                    url: url+"/wp-content/plugins/wpCountdown/admin/save.php?link_id="+link_id,
                    type: "post",
                    data: $("#formSave").serialize(),
                    success: function(d) {
    
                        alert('saved');
                    }
                });
    

In Chrome it more often than not saves fine.

Safari and chrome, the alert() is not called and only sometimes is the information saved.

Questions are: 1. am I calling ajax correctly (i have initiated this in the index file). 2. are there reasons it saves sometimes and not others and appears to work in other browsers.

Apologies, hope this is enough detail to be posting on here for the first time

  • 写回答

1条回答 默认 最新

  • duandunzhuo3234 2015-02-23 17:45
    关注

    You should read the WordPress Codex material on Ajax (http://codex.wordpress.org/AJAX_in_Plugins).

    Ajax calls need to go through a special WordPress handler given by

    admin_url('admin-ajax.php');
    

    and you need a PHP handler function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)