Created
June 2, 2016 04:06
-
-
Save websemantics/449b4f87b75d0edc2e44fe7503e17fb4 to your computer and use it in GitHub Desktop.
Extends Ajax to strictly use Yahoo Query Language for CROSS-DOMAIN Ajax.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax = (function (ajax) { | |
return function (o) { | |
o.dataType = 'json' | |
o.data = { | |
q: 'select * from html where url="' + (o.url + (o.data ? (/\?/.test(o.url) ? '&' : '?') + $.param(o.data) : '') + '" and xpath="*"'), | |
format: 'xml' | |
} | |
o.url = 'http' + (/^https/.test(location.protocol) ? 's' : '') + '://query.yahooapis.com/v1/public/yql?callback=?' | |
o.success = (function (success) { | |
return function (data) { | |
if (success) { | |
success.call(this, data.results[0] || '', 'success') | |
} | |
} | |
})(o.success) | |
return ajax.apply(this, arguments) | |
} | |
})($.ajax) |
Author
websemantics
commented
Jun 2, 2016
- Credits, http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment