[問題] 初碰JQUERY AJAX 麻煩指教一下

看板Ajax作者 (Krel)時間17年前 (2008/10/31 21:28), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串1/2 (看更多)
目前使用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)

10/31 22:40, , 1F
回傳的就放在response阿就是success的第一個參數
10/31 22:40, 1F

10/31 22:49, , 2F
原本是用$('#msg').html(response)但發現沒回傳demook
10/31 22:49, 2F

10/31 22:50, , 3F
所以才在裡面放字串,結果也是沒有出現comeFrom2
10/31 22:50, 3F

10/31 22:56, , 4F
你可以裝firebug debug ajax..
10/31 22:56, 4F
文章代碼(AID): #192mVeE_ (Ajax)
文章代碼(AID): #192mVeE_ (Ajax)