简体   繁体   English

jQuery AJAX从文件中检索SVG-错误:格式不正确

[英]jQuery AJAX retrieve SVG from file - ERROR: 'not well-formed'

I have been using many different svg from inkscape and using .load to a specific container element for a while. 一段时间以来,我一直在使用许多与inkscape不同的svg,并使用.load到特定的容器元素。 I recently tried changing the load to a get (AJAX), mainly to be able to prepend the svg. 我最近尝试将负载更改为get(AJAX),主要是为了能够添加svg。

This worked pefectly, svg prepended to element as should do, problem is I get the console error 'not well-formed' when using the ajax get method of retrieving the svg file. 这项工作很完美,svg像应该做的那样放在元素的前面,问题是当我使用ajax get方法检索svg文件时,出现控制台错误“格式不正确”。 I dont like ignoring errors, but this does interfere with the page content. 我不喜欢忽略错误,但这确实会干扰页面内容。

Didnt think it was an issue with the svg, because it was working previoulsy, just to make sure I checked the required namespaces in svg where included(although using inkscape default metadata from standard save). 不要认为这是svg的问题,因为它工作正常,只是为了确保我检查了svg中包含的所需名称空间(尽管使用了标准保存中的inkscape默认元数据)。 eg: 例如:

<svg      
 xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:ev="http://www.w3.org/2001/xml-events">

Original load Method (No Error): 原始加载方法(无错误):

$('.container-svg').load("img/floorplan/"+ source +".svg", null, function() 
{
   //other things happen
});

New Ajax Method (Error): 新的Ajax方法(错误):

$.get("img/floorplan/"+ source +".svg").done(function( data )
{
    $(".container-svg").prepend($(data).find("svg"));
    //other things happen
});
  • Is this related to the metadata in the svg file? 这与svg文件中的元数据有关吗?
  • should/how do I correct the error? 应该/如何纠正错误?

Figured it out.... $.get() is a shorthand version for $.ajax(), except i think it uses XML as default datatype. 弄清楚了...。$ .get()是$ .ajax()的简写版本,但我认为它使用XML作为默认数据类型。 I thought it would use HTML as default so just used longhand and assigned dataType : 'html' this is now compatible with svg. 我认为它将默认使用HTML,因此只使用了longhand并分配了dataType:'html'现在与svg兼容。

$.ajax(
{
    url: "img/floorplan/"+ source +".svg" ,
    dataType: 'html',
    type: 'GET',
    success: function(data) 
    {         
        $(".container-svg").prepend(data);
    }
});

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

相关问题 XML在jquery中格式不正确 - XML is not well-formed in jquery 使用 XMLHttpRequest 加载 JSON 文件时,Firefox 中出现“格式不正确”错误 - "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest XML 解析错误:使用 dataTable 和文本文件中的数据格式不正确 - XML Parsing Error: not well-formed using dataTable and data from text file javascript的“解析XML时出错:格式不正确” - "Error parsing XML: not well-formed" for javascript javascript格式不正确 - javascript not well-formed 文件上传ajax:您的POST请求的正文格式不正确的multipart / form-data - file upload ajax:The body of your POST request is not well-formed multipart/form-data jquery加载函数在firefox中抛出“XML解析错误:格式不正确”错误 - Jquery load function throws “XML Parsing Error: not well-formed” error in firefox 格式良好的HTML字符串上的jQuery()会导致语法错误,无法识别的表达式 - jQuery() on a well-formed HTML string results in Syntax Error, unrecognized expression 使用AngularJS循环遍历JSON文件时出现“格式不正确”的firefox错误 - “Not well-formed” firefox error while looping through JSON file with AngularJS 为什么会出现“格式不正确”的错误? - Why do I get a “not well-formed” error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM