Skip to content

Instantly share code, notes, and snippets.

@websemantics
Created June 2, 2016 04:06
Show Gist options
  • Save websemantics/449b4f87b75d0edc2e44fe7503e17fb4 to your computer and use it in GitHub Desktop.
Save websemantics/449b4f87b75d0edc2e44fe7503e17fb4 to your computer and use it in GitHub Desktop.
Extends Ajax to strictly use Yahoo Query Language for CROSS-DOMAIN Ajax.
$.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)
@websemantics
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment