通过AJAX将jQuery变量传递给Controller

时间:2018-09-13 18:01:00

标签: javascript c# jquery asp.net-mvc

我正在尝试将变量从GetTelephoneFunction发送到AJAX查询,以便它可以到达控制器,但是我尝试执行的操作不起作用。请帮忙,谢谢。

jQuery:

$.ajax({
        type: "POST",
        url: "/Status/GetUrlSource",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ "url": $("#urlInput").val(), "user": $("#user").val(), "pass":$("#pass").val(),"freq": $("#freqInput").val() }),
        dataType: "html",
        success: function (result, status, xhr) {
        //Code
        }
    function GetUrlTelePhone(html, status, result) {
        var geturlUser = url.split('?username=')[1].split('&password')[0];
        var geturlPass = url.split("&password=")[1];
        var getUrlMain = url.split("?")[0];
        var geturlParameters = url.split("aspx")[1];
        }

控制器

    public string GetUrlSource(string url, string freq, string user, string pass)
    {
        //user = user.Substring(0, 10) != "?" ? "?" + user : user;
        //pass = pass.Substring(0,20) != "&" ? "&" + pass : pass;
        url = url.Substring(0, 4) != "http" ? "http://" + url : url;
        string htmlCode = "";
        using (WebClient client = new WebClient())
        {
            try
            {
                htmlCode = client.DownloadString(url);
            }
            catch (Exception)
            {
                return "Not Found";
            }
        }
        //SqlConnect(url);
        Hangfire(url,freq,user,pass);

        return htmlCode;

    }

0 个答案:

没有答案