Guest User

Untitled

a guest
May 28th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. //BUGFIX: Chromeframe miss some features.
  2. (function($) {
  3. $.oldAjax = $.ajax;
  4.  
  5. $.ajax = function(o) {
  6. // I can't detect it by navigator.userAgent. So I set it on server side.
  7. if (navigator.chromeframe) {
  8. // Chromeframe can't send DELETE and PUT verb.
  9. if (o.type == "DELETE") {
  10. o.type = "POST";
  11. o.data = "_method=delete";
  12. } else if (o.type == "PUT") {
  13. o.type = "POST";
  14. o.data += "&_method=put";
  15. }
  16. }
  17.  
  18. // Chromeframe send incorrect ajax type make rails process the request by */*. The right way is JS. I try many way to avoid this. But I can do this with append .js to url only.
  19. if (o.dataType == "script" && !/\.js$/.test(o.url)) {
  20. o.url += ".js";
  21. // Webkit try parse result to json then raise a syntax error when receive html. It appear in inspector only and user can't see that except u r a developer. The url(end of .js) has told rails how to process my request. So I set dataType as text because I need respondText only. I can parse json myself.
  22. o.dataType = "text";
  23. }
  24.  
  25. $.oldAjax(o);
  26. };
  27. });
Add Comment
Please, Sign In to add comment