我对CefSharps Chromium浏览器真的很陌生,很难弄清楚如何获取jquery ajax请求的结果。
我的第一次尝试是将我的AJAX requesto传递给EvaluateScriptAsync 。 实际上该脚本有效。 它完全符合我的要求,但是我没有得到任何结果/状态代码,因为我的Cef-Task不会等到AJAX完成其工作。
这里是一个示例(只是示例代码):
var tasks = pdBrowser.EvaluateScriptAsync(@"
(function(){
$.ajax({
type: ""POST"",
dataType: ""json"",
cache: false,
url: ""_resources/php/ajaxRequests.php"",
async: false,
data: {
action: ""insertCrossPlatform"",
type: """",
values: JSON.stringify(""foo bar"")
},
success: function(response) {
if (typeof response === 'string' && response.substring(0, 5) == ""ERROR"")
{
return response;
}
else
{
//pageReload();
return ""OK"";
}
},
error: function(xhr, textStatus, errorThrown) {
return errorThrown + ""\n"" + xhr.responseText;
},
complete: function() {
return ""COMPLETE"";
}
});
})();", null);
tasks.ContinueWith(t =>
{
if (!t.IsFaulted)
{
var response = t.Result;
if (response.Success)
{
if (response.Result != null)
{
MessageBox.Show(response.Result.ToString());
}
}
else
{
MessageBox.Show(response.Message, "Ein Fehler ist aufgetreten", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}, TaskScheduler.Default);
之后,我读到有一个SchemeHandler,但是我不正确地了解如何实现它。 谁能帮我吗?
提前致谢。