本文介绍了JSON自动完成与asp.net 3.5框架一起使用,但它不适用于框架2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个小的web服务和一个webmethod用文本框执行自动完成 我所做的就是改变构建用2.0而不是3.5 .. 此外,我在XMLHttpRequest中遇到object XMLHttpRequest错误。 <%@ Page 语言 = C# AutoEventWireup = true CodeFile = Default.aspx.cs 继承 = _默认 %> ; < !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd > < html xmlns = http: //www.w3.org/1999/xhtml\"> < head id = Head1 runat = server > < title > 带有jQuery的自动完成框< / title > < link href = http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css rel = stylesheet 类型 = text / css / > < script 类型 = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js > < / script > < script type = text / javascript src = http://ajax.googleapis.com/ajax/libs/jqueryui/ 1.8.1 / jquery-ui.min.js > < / script > < script 类型 = text / javascript 语言 = javascript > $( document )。ready( function (){ SearchText(); }); function SearchText(){ $( 。autosuggest)。autocomplete({ source: function (request,response) { $ .ajax({ type: POST, contentType: application / json; charset = utf-8, url: WebService.asmx / Mydata, data: {'username':' + request.term + '}, dataType: json,成功: function (data){ response(data.d); },错误: function (结果){ alert(result); } }); } }); } < / 脚本 > < / head > < body > < 表单 id = form1 runat = server > < div class = demo > < div class = ui-widget > < label for = tbAuto > 输入用户名: < / label > < 输入 type = text id = txtSearch class = autosuggest / > < / div > < / form > < / body > < / html > < / div > 解决方案 ( document ) .ready( function (){ SearchText(); }); function SearchText(){ ( 。autosuggest)。autocomplete({ source: function (request,响应){ .ajax({ type: POST , contentType: application / json; charset = utf-8, url: WebService.asmx / Mydata,数据: {'username':' + request.term + '}, dataType: json,成功: function (数据){ response(data.d) ; },错误: function (结果){ alert(result); } }); } }); } < / 脚本 > < / head > < body > < 表单 id = form1 runat = server > < div class = demo > < div class = ui-widget > < label for = tbAuto > 输入用户名: < / label > < 输入 type = text id = txtSearch class = autosuggest / > < / div > < / form > < / body > < / html > < / div > I have a small webservice and a webmethod to perform autocomplete with textboxAll i have done is change build with 2.0 rather than 3.5..Also i have got error in XMLHttpRequest as "object XMLHttpRequest".<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>AutoComplete Box with jQuery</title> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function () { SearchText(); }); function SearchText() { $(".autosuggest").autocomplete({ source: function (request, response) { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService.asmx/Mydata", data: "{'username':'" + request.term + "'}", dataType: "json", success: function (data) { response(data.d); }, error: function (result) { alert(result); } }); } }); } </script></head><body> <form id="form1" runat="server"> <div class="demo"> <div class="ui-widget"> <label for="tbAuto"> Enter UserName: </label> <input type="text" id="txtSearch" class="autosuggest" /> </div> </form></body></html></div> 解决方案 (document).ready(function () { SearchText(); }); function SearchText() {(".autosuggest").autocomplete({ source: function (request, response) {.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService.asmx/Mydata", data: "{'username':'" + request.term + "'}", dataType: "json", success: function (data) { response(data.d); }, error: function (result) { alert(result); } }); } }); } </script></head><body> <form id="form1" runat="server"> <div class="demo"> <div class="ui-widget"> <label for="tbAuto"> Enter UserName: </label> <input type="text" id="txtSearch" class="autosuggest" /> </div> </form></body></html></div> 这篇关于JSON自动完成与asp.net 3.5框架一起使用,但它不适用于框架2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 11:00