简体   繁体   English

脚本注入使用 C# 返回 null

[英]Script Injection returns null using C#

I am trying to add an ajax function to a webpage and executed it using C#.我正在尝试将 ajax 函数添加到网页并使用 C# 执行它。 Here it is my code:这是我的代码:

HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
element.text = "function sayHello() { $.ajax({type: 'GET', url: '/gres/ajax/archive-odds.php',data:'&outcome='+'27498xv498x0x0'+'&provider='+'14',cache:!1,dataType:'xml', success: function (data) { alert('sucess'); }, complete: function () {} }); $('body').html(); }";
head.AppendChild(scriptEl);
object res = webBrowser1.Document.InvokeScript("sayHello");

My code, doesn't gave me any error.我的代码,没有给我任何错误。 But the res object is always null.但是 res 对象始终为空。 Can anybody help me??有谁能够帮助我??

Thanks谢谢

Your js function doesn't return any values.您的 js 函数不返回任何值。

Try something like in this example这个例子中尝试类似的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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