简体   繁体   中英

$.getJSON not working in IE10,

I am trying to make a post request something like this. Following line calls a controller action

$.getJSON(GetPath('/Products/Search'), param, function (data) {
  // do some thing with data
}

GetPath gives me a valid URL

   function GetPath( url ) {

           var protocol = "http://";

           if ('@ApplicationInstance.Application["IsHTTPS"]' == "TRUE")

               protocol = "https://";

           if ('@HttpContext.Current.Request.ApplicationPath' == "/")

               return protocol + window.location.host + url;

           else

       return protocolwindow.location.host+'@HttpContext.Current.Request.ApplicationPath' + url;    

       }

This is perfectly working fine in chrome as well as safari.

But in IE10 getting an error message in console

script1014: invalid character

Is this something to do with Jquery version?

Apperantly IE seems to have problems with accessing files directly (without http server). If you change the request to

$.getJSON(GetPath('http://localhost/Products/Search'), param, function (data) {
  // do some thing with data
}

(assuming that you're running this in localhost environment) then this error should dissappear and your code should work.

cfr. SCRIPT1014: Invalid character ; Getting SCRIPT1014: Invalid character in IE from local js file

also clearing the browser cache sometimes seems to help

return protocolwindow.location.host+'@HttpContext.Current.Request.ApplicationPath' + url;

change

return protocol + window.location.host + '@HttpContext.Current.Request.ApplicationPath' + url;

and getJSON success callback use jQuery.parseJSON

$.getJSON(GetPath('/Products/Search'), param, function (data) {
    var search_results = jQuery.parseJSON(data);
    console.log(search_results);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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