Edi Wang

.NET and Azure Developer

AJAX

Send AntiForgeryToken via jQuery Ajax in ASP.NET Core

In ASP.NET Core, if we use jQuery Ajax to post data to the server, and we want the ValidateAntiForgeryToken attribute to work. We have to do some tricks. The official document didn't document how to do it via jQuery. Let me show you how to do it. Please do read the official document first: https://docs.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-2.1  In my …
.NET AJAX ASP.NET jQuery

JQuery文本框自动完成,通过AJAX调用ASP.NET WebService

最近在搞博客搜索框的自动完成功能,用的是JQuery UI里的autocomplete插件。插件的数据源是用AJAX调用一个WebService,网站后台有个标签库,WebService返回的是符合条件的标签。最终效果如下: 我们先来看WebService的代码,方法很简单: [WebMethod] public List GetAllTagsForAutoComplete(string tagName) { return optTag.GetModelList().Where(p => p.Name.ToLower().StartsWith(tagName.ToLower())).ToList(); }  这个方法的作用是根据输入的内容,检索所有以tagName开头的标签。我没有返回全部标签,是因为autocomplete插件的默认行为不符合我的需求。在默认情况下,如果我输入 …
AJAX ASP.NET AutoComplete jQuery WebService

JQuery AJAX读取ASP.NET WebService泛型方法

这几天在研究JQuery和WebService,被泛型返回类型搞死了。查了很多资料做实验终于搞定了。网上很多垃圾文章的作者都不亲手实验就到处拼凑把东西发上来,太不负责了。下面我发的是100%可用的,经过亲手实验的代码。 首先在WebService上要注意一点,一定记得把[System.Web.Script.Services.ScriptService]这行取消注释,这样脚本才可以调用到WebService。如图: 我用来测试的是我网站的友情链接列表,其WebService方法如下: [WebMethod] public List GetFriendLinks() { return new EdiBlog.Core.FriendLink().GetModelList(); } 经过测试,在浏览器中用GET访问是会爆掉的,所以我们用POST方法去调用。在默认的IIS和ASP. …
AJAX ASP.NET jQuery WebService