javascript - JSONP context problem -


I'm using javascript autocomplete () in a greasemonkey script but it works correctly on my own. I do not want to add JSONP because I want data from any other domain. Code (snippet):

  Function AutoUspe (URL) {this.suggest_url = url; This.keywords = []; This return }; Autosuggest.prototype = {build: function () {return it back; }, Previous suggestions: work () {this.CreateJSONPRequest (this.suggest_url + "foo"); }, CreateGSONPRIEinst: function (url) {var headID = document. Tag elements biatagnam ("head") [0]; Var newScript = document.createElement ('script'); NewScript.type = 'Text / JavaScript'; NewsScript src = url + '& amp; Callback = autosuggest.prototype.JSONCallback '; //newScript.async = true; NewScript.onload = newScript.onreadystatechange = function () {if (newScript.readyState === "weighted" || newScript.readyState === "full") {// Load it again new script .onload = newScript Onreadystatechange = null; If (Newscript & amp; New Script Footnote) {newScript.parentNode.removeChild (Newscript); }}} HeadID.appendChild (newScript); }, JSON callback: function (data) {if (data) {this.keywords = data; This.suggest (); }}, Suggestion: function () {// use this .keywords}}; // textboxes add suggestion box for window.opera.addEventListener ('afterEvent.load', function (e) {var textboxes = document.getElementsByTagName ('input'); for (var i = 0; i  

When you have no context for the prototype directly, this When the JSON call is returned, it is calling autosuggest.prototype.JSON callback , but that function can not be called instead, instead I recommend creating a cover function I am:

  function JSONCallback (data) {var as = new autosuggest (); As.ckeywords = Data; As.suggest (); }  

Or, create a single global auto-suggest object and use it as a callback:

  var globalAS = New autosuggest () "? Http: // example / q ="); // Within the CreateJSONPRequest function, replace this line: newScript.src = url + '& amp; Callback = globalAS.JSONCallback ';  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -