Web浏览器控件中的Ajax请求无法正常工作

时间:2016-07-12 06:58:03

标签: c# ajax asp.net-mvc session

我有一个带有httpGet功能的MVC网站,可以执行此操作

public class TestController : Controller
{
    [HttpGet]
    public JsonResult doSomething()
    {
        if(Session[SessionName.count] == null) 
            Session[SessionName.count] = 0;

        Session[SessionName.count] += 1;
        return Json(Session[SessionName.count], JsonRequestBehavior.AllowGet);
    }
}

在网站上有一个javascript函数可以做到这一点

function testing(){
    $.ajax({
        url: "@Url.Action("doSomething", "Test")",
        success: function (data) {
            alert(data);
        },
        error: function (data) {
            alert("error");
        }
    });
}

最后在我的网页浏览器控件中

public void ShowCount() 
{
    browser.Document.InvokeScript("Testing");
}

每次调用ShowCount()时,Web浏览器控件中的警告框始终为1。

0 个答案:

没有答案