简体   繁体   中英

Read DOM object after the invoke call

How can i read the value of the callback message from a javascript call.

Here is my code:

 private void OnDocumentLoaded(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      CallbackHandler callback = new CallbackHandler(EndRequestNormally, EndRequestWithNoData);
      SendJavaScript(CreateRequestCompleteListenerScript());

        theBrowser.Document.InvokeScript("RequestCompleteListener", new object[] { callback });
        theBrowser.Document.InvokeScript("AjaxObjectHandle", new object[] { _parameters });
    }

 private void EndRequestNormally()
    {
        SetWebWidgetWindowSize();
    }

 private void SendJavaScript(string script)
    {
        theBrowser.Document.InvokeScript("eval", new object[] {script});
    }

 private string CreateRequestCompleteListenerScript()
    {
        StringBuilder script = new StringBuilder();
        script.AppendLine("var RequestCompleteListener = function(callback) {");
        script.AppendLine("    var internalCallback = {");
        script.AppendLine("        handleCallback:function(message, params){");
        script.AppendLine("            if (message == null){");
        script.AppendLine("                 callback.HandleNullMessage();");
        script.AppendLine("            } else {");
        script.AppendLine("                 callback.HandleRequestComplete();");
        script.AppendLine("            }");
        script.AppendLine("        }");
        script.AppendLine("    }");
        script.AppendLine("    UpdateAjaxObject.addListener('requestcomplete', internalCallback.handleCallback, internalCallback);");
        script.AppendLine("};");
        return script.ToString();
    }



    [System.Runtime.InteropServices.ComVisible(true)]
    public class CallbackHandler
    {
        public CallbackHandler(VoidHandler requestCompleteAction, VoidHandler nullMessageAction)
        {
            _requestCompleteAction = requestCompleteAction;
            _nullMessageAction = nullMessageAction;
        }

        private VoidHandler _requestCompleteAction;
        private VoidHandler _nullMessageAction;
        private bool _requestCompleted;

        [System.Runtime.InteropServices.DispId(0)]
        public void HandleRequestComplete()
        {
            if (!_requestCompleted)
                _requestCompleteAction();
            _requestCompleted = true;
        }

        [System.Runtime.InteropServices.DispId(1)]
        public void HandleNullMessage()
        {
            if (!_requestCompleted)
                _nullMessageAction();
        }
    }

The above code is just making the call.

What i want is, to read the value in the message after the call.

The image below contains the values in the AJAX object

I want to get the count of the binshares under tradeschedule. DOM的图片

Is there a way to that?

Any help is appreciated.

Thanks

Do you mean you just want to get at it with JavaScript? <script>alert(AjaxObject.messages.tradeSchedule.binShares[0]);</script> You didn't expand the binShares array so I'm not sure what's under there.

I see you made changes, you want the length of binShares, do this...

<script>alert(AjaxObject.messages.tradeSchedule.binShares.length);</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM