JASON AJAX POST方法不使用ASP.NET 2.0,但使用3.5 [英] JASON AJAX POST METHOD NOT WORKING WITH ASP.NET 2.0 BUT WORKS WITH 3.5

查看:56
本文介绍了JASON AJAX POST方法不使用ASP.NET 2.0,但使用3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的webmethod从sql表返回简单的数据集...

如果我将asp.net框架设置为3.5但是在将其设置为2.0后它无法工作



i在default.aspx页面上提到了以下代码

<%@ Page Language =C#AutoEventWireup =trueCodeFile =Default.aspx。 csInherits =_默认%>



<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">

< html xmlns =http://www.w3.org/1999/xhtml >

< head id =Head1runat =server>

< title>带有jQuery的自动完成框< / title>

< link href =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css

rel = stylesheettype =text / css/>

< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.4 .2 / jquery.min.js>< / script>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js>< / script>

< script type =text / javascript>

$(document).ready(function(){

SearchText();

});

函数SearchText(){

alert('IN');

$(。autosuggest)。自动完成({





来源:功能(请求,响应){

$ .ajax({

类型:POST,

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

url:../ Default.aspx / Mathata,

data:{'username':'+ JSON.stringify (document.getElementById('txtSearch')。value)+'},

dataType:json,

成功:函数(数据){

响应(data.d);

},

错误:函数(结果){

alert(result);

}

});

}

});

}

< / script>

< / head>

< body>

< form id = form1runat =server>





< label for =tbAuto>

输入用户名:

< / label>

< input type =textid =txtSearchclass =autosuggest/>





< / form>

< / body>

< ; / html>

解决方案

(document).ready(function(){

SearchText();

});

函数SearchText(){

alert('IN');


(。 autosuggest)。自动完成({





来源:功能(请求,响应){


.ajax({

类型:POST,

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

url:../ Default.aspx / Mathata,

data:{'username':'+ JSON.stringify (document.getElementById('txtSearch')。value)+'},

dataType:json,

成功:函数(数据){

响应(data.d);

},

错误:函数(结果){

alert(result);

}

});

}

});

}

< / script>

< / head>

< body>

< form id = form1runat =server>





< label for =tbAuto>

输入用户名:

< / label>

< input type =textid =txtSearchclass =autosuggest/>





< / form>

< / body>

< ; / HTML>


i have small webmethod returning simple dataset from sql table...
this works if i set asp.net framework as 3.5 but after setting it to 2.0 its not working

i have done below mention code on default.aspx page
<%@ 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">
$(document).ready(function () {
SearchText();
});
function SearchText() {
alert('IN');
$(".autosuggest").autocomplete({


source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../Default.aspx/Mydata",
data: "{'username':'" + JSON.stringify(document.getElementById('txtSearch').value) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert(result);
}
});
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">



<label for="tbAuto">
Enter UserName:
</label>
<input type="text" id="txtSearch" class="autosuggest" />



</form>
</body>
</html>

解决方案

(document).ready(function () {
SearchText();
});
function SearchText() {
alert('IN');


(".autosuggest").autocomplete({


source: function (request, response) {


.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../Default.aspx/Mydata",
data: "{'username':'" + JSON.stringify(document.getElementById('txtSearch').value) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert(result);
}
});
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">



<label for="tbAuto">
Enter UserName:
</label>
<input type="text" id="txtSearch" class="autosuggest" />



</form>
</body>
</html>


这篇关于JASON AJAX POST方法不使用ASP.NET 2.0,但使用3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆