jquery - 发布数据 JQuery UI 选项卡 1.10

标签 jquery jquery-ui zend-framework post

我刚刚从JQ UI 1.8.23切换到1.10。对于这个版本,ajaxOptions已被弃用,现在ui.ajaxSettings已被弃用而是使用。

这就是我的代码的样子:

$( "#tabs" ).tabs({
        ajaxOptions: {
            type : 'POST',
            data : 'format=html',
            error: function( xhr, status, index, anchor ) {
                $( anchor.hash ).html(
                    "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                    "If this wouldn't be a demo. " );
            },
            success: function() { 
                *Something in here*
            }
        }
    });

一切都很好。现在新代码:

$( "#tabs" ).tabs({
         beforeLoad: function( event, ui ) {
             ui.ajaxSettings.type = 'POST';
             ui.ajaxSettings.data = 'format=html';
             ui.jqXHR.error(function() {
                 ui.panel.html(
                 "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                 "If this wouldn't be a demo." );
                });  
             ui.jqXHR.success(function(){
*something in here*
                });
        }
    });

因此,我需要将此数据 format=html 发布到我的服务器,但在新版本中,发送到服务器的发布变量为空。没有任何内容发送到服务器。另外,如果我想在我的 php 脚本 中获取 POST 变量,则数组为空。顺便说一句,我正在使用 ZEND 。我需要通过 POST 发送它 - 没有办法解决它。

感谢您的帮助

最佳答案

如果您查看 jQuery.ajax 的源代码,在第 486 行,您将看到它将数据添加到 url 中。然后在第 532 行,它调用 beforeSend 方法,该方法触发 jQuery UI 选项卡中的 beforeLoad 事件。

所以你需要做的就是修改 url 而不是数据:

$( "#tabs" ).tabs({
    beforeLoad: function( event, ui ) {
        ui.ajaxSettings.type = 'POST';
        ui.ajaxSettings.url += ( /\?/.test( ui.ajaxSettings.url ) ? "&" : "?" ) + 'format=html';
        ui.jqXHR.error(function() {
            ui.panel.html(
                "Couldn't load this tab. We'll try to fix this as soon as possible. " +
                "If this wouldn't be a demo." );
        });  
        ui.jqXHR.success(function(){
            *something in here*
        });
    }
});

关于jquery - 发布数据 JQuery UI 选项卡 1.10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14480797/

相关文章:

zend-framework - Zend 框架 1.8+ : How to automatically set the application environment?

php - 将数据从 View 传递到 Controller (Zend)

javascript - Fancybox 不是函数

jquery - 将 div 克隆到 obj 中并对其进行操作

javascript - 结合 HTML5、CSS 和 JS

jquery-ui - KendoUI 像 JQueryUI 一样可排序

jQuery ui shake 效果作为副作用移动其他元素

php - 为什么将框架文件夹放在公共(public)根目录之外更安全?

javascript - 如何在内部 html 中获取特定类

jquery - 圆形 slider 选择