简体   繁体   English

XML解析错误:找不到根元素(空内容)Django

[英]XML Parsing error: no root element found (empty content) Django

I am using ajax to connect to a view in my web application. 我正在使用ajax连接到我的Web应用程序中的视图。

  $.ajax({
        url: url,
        type: 'PATCH',
        success: function() {
          var d = new Date();
          img = e.target.parentElement.parentElement.getElementsByTagName('img')[0];
          if (img.src.includes("?")){
            img.src = img.src.split("?")[0] + '?' + d.getTime();
          } else {
            img.src = img.src + '?' + d.getTime();
          }

        },
    });

When I click on the button that triggers this, everything works, but I get an XML Parsing error . 当我点击触发此按钮的按钮时,一切正常,但我收到XML Parsing error According to the other questions on stack exchange, this might be beacuse of an empty content. 根据堆栈交换的其他问题,这可能是因为空内容。 When I use the firefox developer tools, the content of the reverse of the concerned view is indeed empty, because of which, I think, firefox interprets it as an xml. 当我使用firefox开发人员工具时,相关视图reverse的内容确实是空的,因此,我认为,firefox将其解释为xml。 My problem is, that I do not know how to fill the content. 我的问题是,我不知道如何填写内容。 In my view, I changed return Response(status=200) to return Response(status=200, content_type='image/jpeg') , because the view does something to an image. 在我看来,我更改了return Response(status=200)return Response(status=200, content_type='image/jpeg') ,因为视图对图像有所作为。 But still the content seems to stay empty and I still get the error. 但是内容似乎仍然是空的,我仍然得到错误。 I don't know how else to alter the content type than by specifying it in the response. 我不知道如何更改内容类型,而不是在响应中指定它。 I only get this error in firefox, not in chrome. 我只在firefox中得到此错误,而不是在chrome中。

结果我只需要将content_type设置为text/html ...

The server response is missing header Content-Type . 服务器响应缺少标题Content-Type So the JavaScript 'success' handler cannot parse correctly the response body. 所以JavaScript'success'处理程序无法正确解析响应体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM