2017-01-26 5 views
-1

Webページにajax関数を追加しようとしていて、C#を使用して実行しました。ここに私のコードです:Script InjectionはC#を使用してnullを返します

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"); 

私のコードは、何かエラーをされていません。しかし、resオブジェクトは常にnullです。誰も私を助けることができますか?

ありがとうございました

答えて

1

js関数は値を返しません。私はAjaxの部分の先頭にリターンを追加する場合

は、その仕事が希望、this example

+0

のようなものを試してみてください? –

+0

いいえ、このようなものを試すことができますhttp://stackoverflow.com/a/2592780/2921949 –

関連する問題