作者martone (Krel)
看板Ajax
標題[問題] 初碰JQUERY AJAX 麻煩指教一下
時間Fri Oct 31 21:28:07 2008
目前使用jQuery的ajax,可是卻得不到回傳值。請各位指教一下
在header裡
<script type="text/javascript" src="js/jquery-1.2.6.js"></script>
<script type="text/javascript">
function showMsg(e) {
$(e.target).attr('disabled', true);
$.ajax({
url: '
http://127.0.0.1:8081/KH/forajax.jsp',
error: function(xhr) {
alert('Ajax request 發生錯誤');
},
success: function(response) {
$('#msg').html('demoOK');
}
});
}
function msg2(e){
$('#msg').html('comeFrom2');}
</script>
有個按鈕
<input type="button" value="Click Me" onclick="showMsg()"/>
我的jsp內有
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="
http://java.sun.com/jsp/jstl/core" %>
<c:out value="demook"></c:out>
第一次使用ajax,卻不知道失敗原因在哪,就取不到回傳值
請各位幫忙看一下 謝謝^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.127.2
※ 編輯: martone 來自: 118.170.127.2 (10/31 21:31)
1F:推 tn801534:回傳的就放在response阿就是success的第一個參數 10/31 22:40
2F:→ martone:原本是用$('#msg').html(response)但發現沒回傳demook 10/31 22:49
3F:→ martone:所以才在裡面放字串,結果也是沒有出現comeFrom2 10/31 22:50
4F:推 tn801534:你可以裝firebug debug ajax.. 10/31 22:56