ramesh santha

ramesh santha

  • NA
  • 5
  • 921

Undefined value while executing JS function using V8Engine

Dec 21 2018 12:33 AM
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:
  1. function Execute(paraList){  
  2. var finalUrl = "http://172.29.134.69:9006/api/Line/GetStationDefectsByStationId?stationId=1";  
  3. var response=get(finalUrl,function(){var resp=this.response;return resp;});  
  4. return response;  
  5. }  
  6. function get(url, callback) {  
  7. var xhr = new XMLHttpRequest();  
  8. xhr.open("GET",url, true);  
  9. xhr.send("");  
  10. xhr.onreadystatechange = function () {  
  11. if (xhr.readyState == 4) {  
  12. if (typeof callback === "function") {  
  13. callback.apply(xhr);}  
  14. }  
  15. };  
  16. }  
C# Code:calling javascript function from c# using V8ScriptEngine
  1. V8ScriptEngine _v8Engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging);  
  2. _v8Engine.Execute(Script_Text);  
  3. _v8Engine.AddCOMType("XMLHttpRequest""MSXML2.XMLHTTP");  
  4. object returnedVal = _v8Engine.Script.Execute();  
  5. return returnedVal;