无法从asp.net上的客户端连接到web方法

时间:2015-07-03 22:14:44

标签: c# asp.net ajax webmethod

我正在尝试使用ajax函数从html页面连接到web方法

    $.ajax({
                url: "http://localhost:43599/WebForm1.aspx/GetWeatherResultsbyscript",
                cache: false,
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data:{Zip:input},
                dataType: 'json',
                success: function (data,result) {
                    alert(result.d);
                },
                error: function () { alert(" Server not found"); }
            });

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    private object GetWeatherResultsbyscript(string Zip) {

        ServiceReference1.ForecastReturn result = new ServiceReference1.ForecastReturn();
        ServiceReference1.WeatherSoapClient client = new ServiceReference1.WeatherSoapClient();
        result = client.GetCityForecastByZIP(Zip);
        return (result);


    }

结果我找不到该服务器,但如果我删除了ajax函数中的行

 contentType: "application/json; charset=utf-8",
                 dataType: "json",`

结果我得到'未定义'。

任何人都可以告诉我在连接到网络方法时的错误吗?

1 个答案:

答案 0 :(得分:0)

该方法应该是公开的。请尝试下面的代码,

public static function addedPaginatedUrls($crawl_id, $cmp_crawl_id) {
    return UrlStatus::paginated($crawl_id)
        ->whereNotIn('url.url', function ($sql) use($cmp_crawl_id) {
            // START REPEATED CODE
            UrlStatus::repeatedCodeRefractoringNameItWhateverYouWant($sql, $cmp_crawl_id)
            // END REPEATED CODE
            ->where('url_status.pagination', '<>', '')
            ->whereNotNull('url_status.pagination');
        });
}

public static function addedCanonicalUrls($crawl_id, $cmp_crawl_id) {
    return UrlStatus::canonical($crawl_id)
        ->whereNotIn('url.url', function ($sql) use($cmp_crawl_id) {
            // START REPEATED CODE
            UrlStatus::repeatedCodeRefractoringNameItWhateverYouWant($sql, $cmp_crawl_id)
            // END REPEATED CODE
            ->whereNotNull('url_status.canonical');
        });
}

此外,

网址中缺少应用名称:http://localhost:43599/application name / WebForm1.aspx