Skip to content

Instantly share code, notes, and snippets.

@lukeIam
Created April 18, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeIam/31fef40e9c783ddddc5e to your computer and use it in GitHub Desktop.
Save lukeIam/31fef40e9c783ddddc5e to your computer and use it in GitHub Desktop.
GM Test Script for GM_xmlhttpRequest und jQuery.Deferred
// ==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