我有一个简单的查找表单,从asp服务器获取数据。用户提交表单后,表格会在同一页面上更新。我试图将查找转换为使用Ajax,以便只重新加载表而不是整个页面。但我如何传递一个asp变量作为数据值传递给服务器?以及我如何解析从asp服务器返回的数据?我目前如何设置我没有得到任何回应。如果我硬编码的数据值,并提醒“测试”阿贾克斯调用工程..任何帮助的noob将不胜感激!如何用jQuery ajax解析asp响应?
getinfo.asp
<form name="form" method="get" action="getinfo.asp">
<input id="appendedInputButton" name="txtsearch" value="<%=txtSearch%>" type="text">
<button id="submitform" type="submit" onclick="event.preventDefault();" >Search</button>
</form>
<div id="showresults">
<table>
<tr>
<td>Name: <%=name%></td>
<td>Email: <%=email%></td>
<td>Phone: <%=phone%></td>
</tr>
</table>
</div>
<script>
$('#submitform').click(function() {
$.ajax({
url: "getinfo.asp",
data: {
txtsearch: $('#appendedInputButton').val()
},
type: "GET",
dataType : "html",
success: function(html) {
$('#showresults').html(html, '#showresults');
},
error: function(xhr, status) {
alert("Sorry, there was a problem!");
},
complete: function(xhr, status) {
alert("The request is complete!");
}
});
});
</script>
这些是评论,而不是答案。 – GreatBigBore
这些建议都失败了吗?您的getinfo.asp页面是否真的为您的AJAX生成html代码? – MonkeyZeus
我的不好。我专注于他的问题,而不是仅仅因为他的代码无法工作。所以我不会让我撤销downvote。安慰:无论如何,它使我成为一个声望点。 – GreatBigBore