jquery - How to send and retrieve cross-domain ajax data in userscript -


i use code store , retrieve ajax data via http://openkeyval.org/

 $.ajax({    /*   send data    */         url: "http://api.openkeyval.org/store/",         data: "test-key-data=" + json.stringify([123,456]),         datatype: "jsonp",         success: function(data){             console.log(data);         }  });   $.ajax({     /*   retrieve data     */         url: "http://api.openkeyval.org/test-key-data",         datatype: "jsonp",         success: function(data){             console.log(data);         }  });  

everything work fine in chrome javascript console in userscript error this

uncaught referenceerror: jquery110208458673823624849_1375932537303 not defined

i try use gm_xmlhttprequest retrieve data

gm_xmlhttprequest({     method: "get",     url: "http://api.openkeyval.org/test-key-data",     onload: function(response) {         console.log(response.responsetext);     } }); 

but seem openkeyval doesn't accept data via post/get method , log result when access directly url of browser this

{"error":"not_found","documentation_url":"http://openkeyval.org/"}

i include jquery , work fine code
// @require http://code.jquery.com/jquery-latest.min.js

i try use greasemonkey/jquery xhr bridge out change other code this
// @require http://courses.ischool.berkeley.edu/i290-4/f09/resources/gm_jq_xhr.js

and try use openkeyval official javascript library code this
// @require http://cdn.openkeyval.org/statics/openkeyval.packed.js
and retrieve data code this

var ourcallback = function(value, key) {   console('the value of ' + key ' + ' + value); }; window.remotestorage.getitem('test-key-data', ourcallback); 

still got error error: unexpected string

please help, mess more 10 hours.
thank much.

it $.ajax trigger error event function
gm_xmlhttprequest can retrieve mistype data,
try looking datatype: "jsonp" in gm_xmlhttprequest , got jsonp header content-type "application/javascript" or "application/json" , first 1 work well.

my new code retrieve data this

gm_xmlhttprequest({     method: "get",     url: "http://api.openkeyval.org/test-key-data?nocache=" + new date(),     headers: {            "content-type": "application/javascript"     },     onload: function(response) {         console.log(response.responsetext);     } }); 

and retrieve data using $.ajax trigger error event function still send data.
try both content-type on gm_xmlhttprequest , still not work.

code store data this

$.ajax({    /*   send data    */         url: "http://api.openkeyval.org/store/",         data: "test-key-data=" + json.stringify(myvarobject),         datatype: "jsonp"  });  

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -