-
-
Save lukeIam/31fef40e9c783ddddc5e to your computer and use it in GitHub Desktop.
GM Test Script for GM_xmlhttpRequest und jQuery.Deferred
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
// ==UserScript== | |
// @name Test | |
// @namespace Test | |
// @description Test | |
// @include http://www.geocaching.com/geocache/* | |
// @version 1 | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
console.log("start"); | |
var test = function(){ | |
var d = new $.Deferred(); | |
GM_xmlhttpRequest({ | |
url: "http://pastebin.com/raw.php?i=WAB3r0Y9", | |
method: "POST", | |
onload: function(e){ | |
console.log("response text: \n" + e.responseText); | |
console.log("Deferred: \n" + d); | |
d.resolve(JSON.parse(e.responseText)); | |
}, | |
onerror: function(e){ | |
console.log("status text: \n" + e.statusText); | |
console.log("Deferred: \n" + d); | |
d.reject(e.statusText); | |
} | |
}); | |
return d.promise(); | |
}; | |
test().done(function(data){ | |
console.log("data:" + data); | |
console.log("name:" + data.Herausgeber); | |
}); | |
console.log("end"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment