weixin_33720956 2015-01-24 23:24 采纳率: 0%
浏览 52

$ .ajax()与Django失败

I'm trying to get a static file (a js script) from django (development server) using jquery ajax but something is preventing the $.ajax promise to resolve.

Here's my ajax call :

    $.when(
        $.ajax({dataType: "script", cache: true, url: "/static/ajax_upload/js/jquery.iframe-transport.js"}),
        $.ajax({dataType: "script", cache: true, url: "/static/ajax_upload/js/ajax-upload-widget.js"})
    ).then(function() {
        console.log( "Load was performed." );
        AjaxUploadWidget.autoDiscover();
        $("#level-modal").foundation("reveal", "open");
    }, function () { alert("An error occured, try reloading the page."); });

Nothing in the then function is called, success nor failure.

The weird thing is that the same ajax call with files from google works :

    $.when(
        $.ajax({dataType: "script", cache: true, url: "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"}),
        $.ajax({dataType: "script", cache: true, url: "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"})
    ).then(function() {
        console.log( "Load was performed." );
        AjaxUploadWidget.autoDiscover();
        $("#level-modal").foundation("reveal", "open");
    }, function () { alert("An error occured, try reloading the page."); });

I think something might be wrong with my responses headers but I get a 200 status and I ain't an expert in Http.

Response from django :

HTTP/1.0 200 OK
Date: Sat, 24 Jan 2015 22:57:35 GMT
Server: WSGIServer/0.1 Python/2.7.3
Last-Modified: Sat, 24 Jan 2015 18:45:52 GMT
Content-Length: 9476
Content-Type: application/javascript

Response from google :

access-control-allow-origin:*
alternate-protocol:443:quic,p=0.02
cache-control:public, max-age=31536000
content-encoding:gzip
content-length:29524
content-type:text/javascript; charset=UTF-8
date:Sat, 24 Jan 2015 22:57:38 GMT
expires:Sun, 24 Jan 2016 22:57:38 GMT
last-modified:Fri, 19 Dec 2014 15:56:50 GMT
server:sffe
status:200 OK
timing-allow-origin:*
vary:Accept-Encoding
version:HTTP/1.1
x-content-type-options:nosniff
x-xss-protection:1; mode=block
  • 写回答

1条回答 默认 最新

  • weixin_33691700 2015-01-25 02:54
    关注

    After going through everything I could think of,
    I finally found the problem.
    It was dajaxice. It is apparently overriding some things in jquery.
    After commenting it out, I was able to get the normal behavior.

    I found out that the problem can be resolved for people using jquery by adding DAJAXICE_XMLHTTPREQUEST_JS_IMPORT = False in your settings.py

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀