With the latest update, my plugin crash
PS: JavascriptCode:RequestDataMySQL : function(prmt){ var SystemNet = importNamespace("System.Net"); var WebClient = new SystemNet.WebClient(); UrlR = this.Config.Options["URL"]+"key="+this.Config.Options["MySQLKEY"]+"&"+prmt; SrvResponse = System.WebClient.DownloadString(UrlR); return SrvResponse; }
Solved Error using webrequest with JavaScript
Discussion in 'Rust Development' started by LEO318x, Jan 27, 2015.
-
Wulf Community Admin
-
EDIT: Ignore this, did not know there was a api about it
[DOUBLEPOST=1422566451][/DOUBLEPOST]I'm testing the WebRequests using the API providing by oxide, but I have some problems T_T
Lua work fine!
Code:function PLUGIN:cmdtestR() local enlace = "http://localhost/rust/rust2/request.php" local datos = "?key=test" webrequests.EnqueueGet(enlace..datos, function(code, response) print(code) end, self.Object) end
Code:ReqWeb : function(){ enlace = "http://localhost/rust/rust2/request.php"; datos = "?key=test"; webrequests.EnqueueGet(URL, data, function(code, response){print(code+"|----|"+response);}, this.Object); },
Another way in Javascript but again not work
Code:ReqWeb : function(){ enlaced = "http://localhost/rust/rust2/request.php"; datos = "?key=test"; function test(par, par2){ print(par); print(par2); }; webrequests.EnqueueGet(enlaced+datos, test(code, response), this.Object); },
Any ideas? Thanks -
Try defining the callback as a variable (sorry I can't test this at the moment):
Code:ReqWeb: function(){ enlaced = "http://localhost/rust/rust2/request.php"; datos = "?key=test"; testCb = function(code, response) { print(code); print(response); }; webrequests.EnqueueGet(enlaced+datos, testCb, this.Object); },
-
-
Sorry re-read the error... can you try passing "this" as the last parameter to EnqueueGet?
-
[DOUBLEPOST=1422632968,1422571659][/DOUBLEPOST]Solved, Solution Here:
Code:var jstest = { Title : "Javascript Test", Author : "Nogrod", Version : V(1, 0, 0), HasConfig : true, OnServerInitialized : function () { webrequests.EnqueueGetHook("http://loripsum.net/generate.php?p=1&l=short", "RequestResult", this.Plugin); }, RequestResult : function (code, response) { print(code+"|----|"+response); } }
http://oxidemod.org/threads/declaring-global-variables-with-javascript.6608/#post-62931
Thanks to Nogrod