升级到1.5版时,Jquery的Ajax错误 [英] Jquery ajax error when upgrading to v1.5

查看:136
本文介绍了升级到1.5版时,Jquery的Ajax错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从v1.4.4升级到1.5版。我想我已经找到低于

I upgrading from v1.4.4 to v1.5. I think I have found the problem below

$(document).ready(function(){

    // Get token on page load.
    update_csrf_token();

该功能看起来像这样... EDITED

function update_csrf_token()
{
    $.ajax({
        type: "GET",
        url: "<?php echo site_url('includes/csrf_token/'); ?>",
        dataType: "json",
        jsonp: false,
        jsonpCallback: "callbackName",
        success: function(data) {
            csrf_token = data.csrf_token;
            return data.csrf_token;
        }
    });  
}

我看着萤火虫为Ajax请求,它似乎增加?_ = 1297353567948 的url这使得CSRF令牌不会产生的结束。 我如何摆脱这还是新到1.5并没有什么我可以做什么? 谢谢

I looked in firebug for the ajax request and it seems to add ?_=1297353567948 to the end of the url which makes the csrf token not generate. How do i get rid of this or is it new to 1.5 and nothing I can do? Thanks

推荐答案

jQuery的1.5会自动添加一个随机的回调参数,但你可以通过设置覆盖它的 JSONP jsonpCallback jQuery的AJAX的设置。

jQuery 1.5 will automatically add a random callback parameter, but you can override it by setting the jsonp and jsonpCallback jQuery ajax settings.

jQuery的AJAX API

在jQuery 1.5,从添加设置JSONP选项设置为false prevents的jQuery   ?回调字符串的URL或试图使用=?对于转型。在这种情况下,   你也应该明确设置jsonpCallback设置。例如,    {JSONP:假的,jsonpCallback:callbackName}

As of jQuery 1.5, setting the jsonp option to false prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, { jsonp: false, jsonpCallback: "callbackName" }.

下划线参数(?_ = ... )是包含一个不断变化的时间戳从而使请求的URL总是出现一些浏览器之前从来没有见过一个参数并迫使实际的HTTP请求。真正的设置为阿贾克斯()呼叫(或:该参数可以通过启用缓存,加入缓存中删除全局设置: jQuery.ajaxSetup({缓存:真}); 的默认设置为用的dataType 剧本 JSONP

The underscore parameter (?_=...) is a parameter containing a changing timestamp thus making the request URL to always appear something that the browser has never seen before and forcing an actual HTTP request. The parameter can be removed by enabling caching by adding cache: true setting to the .ajax() call (or by global settings: jQuery.ajaxSetup({cache:true});. The setting defaults to true with dataTypes script and jsonp.

这篇关于升级到1.5版时,Jquery的Ajax错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆