I am calling Execute method of javascript function from C# using V8ScriptEngine but i got undefined value in C#.What should i change in Javascript function? How to know callback function is called or not? Also please suggest other ways to call api from Javascript using ClearScript(V8ScriptEngine).
Javascript Function:
- function Execute(paraList){
- var finalUrl = "http://172.29.134.69:9006/api/Line/GetStationDefectsByStationId?stationId=1";
- var response=get(finalUrl,function(){var resp=this.response;return resp;});
- return response;
- }
- function get(url, callback) {
- var xhr = new XMLHttpRequest();
- xhr.open("GET",url, true);
- xhr.send("");
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- if (typeof callback === "function") {
- callback.apply(xhr);}
- }
- };
- }
C# Code:calling javascript function from c# using V8ScriptEngine
- V8ScriptEngine _v8Engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);
- _v8Engine.Execute(Script_Text);
- _v8Engine.AddCOMType("XMLHttpRequest", "MSXML2.XMLHTTP");
- object returnedVal = _v8Engine.Script.Execute();
- return returnedVal;