我想用jQuery調用ajax函數。這裏是我的樣品編碼使用jQuery調用ASP.NET AJAX頁面
<script src="js/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
debugger
$("#btnSubmit").click(function(e) {
e.preventDefault();
if ($("#txtUserName").val() == '')
alert("Please enter the UserName");
else
sendData($("#txtUserName").val());
});
function sendData(sUserName) {
debugger
var loc = window.location.href;
loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Recipe3.aspx" : loc;
' $.ajax({
debugger
type: "POST",
url: loc + "/CheckUserName",
data: '{"sUserName":"' + sUserName + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.d)
alert("The User Name is valid");
else
alert("The User Name is invalid")
},
error: function() {
alert("An unexpected error has occurred during processing.");
}
});
}
});
</script>
這是什麼意思:loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Recipe3.aspx" : loc;
現在我明白了,謝謝你 – user998405