cefsharp获取ajax返回值,javascript - CefSharp - Get result of AJAX request - Stack Overflow

在尝试使用CefSharp的Chromium浏览器获取jQuery AJAX请求的结果时遇到了问题。尽管AJAX请求能够正常工作,但Cef-Task不会等待其完成。试图通过EvaluateScriptAsync方法传递AJAX请求,但没有成功获取到结果或状态码。了解到可以使用SchemeHandler,但不清楚如何正确实现。寻求帮助以解决如何在CefSharp中获取AJAX请求的完整响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am really new to CefSharps Chromium browser and have difficulty figuring out how to get the result of a jquery ajax request.

My first attempt was to pass my AJAX requesto to EvaluateScriptAsync. In fact the script works. It does exactly what I want, but I do not get any results/status codes, because my Cef-Task does not wait until AJAX has completed its work.

Here an example (just a sample code):

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

Afterwards I have read that there is a SchemeHandler, but I do not properly understand how to implement it. Can anyone help me out?

Thanks in advance.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值