$.ajax({
type: "GET",
url: "something.html",
dataType: "xml",
success:function(data){} ,
});
The content while accessing "something.html" is an XML but the above call is failed where if I use "something.xml" it is working fine.
访问“某物”时的内容。html是XML,但是上面的调用失败了,如果我使用“某某东西”。它运行得很好。
Is it possible to make jQuery to forcefully evaluate the data as XML, without worrying about the file extension?
是否可以让jQuery以XML的形式强制评估数据,而不用担心文件扩展?
2 个解决方案
#1
2
Your problem has nothing to do with the file extension but with the MIME type your server is sending. jQuery expects as per dataType Setting that your server is going to send response as text/xml whereas your server might be sending MIME text/html so its throwing error as kgiannakakis pointed out.
您的问题与文件扩展无关,而是与您的服务器正在发送的MIME类型有关。jQuery期望根据数据类型设置,您的服务器将以文本/xml的形式发送响应,而您的服务器可能发送MIME文本/html,因此如kgiannakakis指出的那样,抛出错误。
#2
2
According to the documentation the dataType option is used to define the expected type of data. Extension is irrelevant. The MIME header will be used when no dataType is set.
根据文档,dataType选项用于定义预期的数据类型。扩展是无关紧要的。当没有设置数据类型时,将使用MIME头部。
#1
2
Your problem has nothing to do with the file extension but with the MIME type your server is sending. jQuery expects as per dataType Setting that your server is going to send response as text/xml whereas your server might be sending MIME text/html so its throwing error as kgiannakakis pointed out.
您的问题与文件扩展无关,而是与您的服务器正在发送的MIME类型有关。jQuery期望根据数据类型设置,您的服务器将以文本/xml的形式发送响应,而您的服务器可能发送MIME文本/html,因此如kgiannakakis指出的那样,抛出错误。
#2
2
According to the documentation the dataType option is used to define the expected type of data. Extension is irrelevant. The MIME header will be used when no dataType is set.
根据文档,dataType选项用于定义预期的数据类型。扩展是无关紧要的。当没有设置数据类型时,将使用MIME头部。