美文网首页
Jquery ajax parsererror

Jquery ajax parsererror

作者: 福瑞德牧 | 来源:发表于2018-11-13 20:47 被阅读0次

    这种是因为后台返回的数据XML格式不正确

    源码如下:

    define( [

    "../core"

    ],function(jQuery) {

    "use strict";

    //Cross-browser xml parsing

    jQuery.parseXML=function(data) {

    varxml;

    if(!data||typeofdata!=="string") {

    returnnull;

    }

    //Support: IE 9 - 11 only

    //IE throws on parseFromString with invalid input.

    try{

    //    调用的是window的方法,所以前台是无能为力的

    xml=(new window.DOMParser() ).parseFromString( data,"text/xml");

    }catch( e ) {

    xml=undefined;

    }

    if(!xml||xml.getElementsByTagName("parsererror").length) {

    jQuery.error("Invalid XML:"+data );

    }

    returnxml;

    };

    returnjQuery.parseXML;

    } );

    相关文章

      网友评论

          本文标题:Jquery ajax parsererror

          本文链接:https://www.haomeiwen.com/subject/tixrfqtx.html