0
我正在製作一個JSP應用程序來調用對Servlet的Ajax請求。我參考了How to use servlets and Ajax。如何通過Servlet從Ajax獲得HTML響應
我在加入responseText
作爲我的div的innerHTML
時遇到問題。我試過
$('#testdiv').html(responseText);
但它顯示爲文本而不是HTML。
我的代碼是:-----------------
function getdata(){
var mobile = document.loyaltyForm.mobile.value;
var code = document.loyaltyForm.mobilecode.value;
var response = '';
var testdiv = document.getElementById("testdiv");
// Locate HTML DOM element with ID "somebutton" and assign the following function to its "click" event...
$.post('loyal', {mob:mobile,mobilecode:code}, function(responseText) { // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response text...
alert('Response:'+responseText);
});
}
對不起,但你的問題是無法理解的。它是在HTML頁面上打印文本,因爲這就是你說的你想要的 - 你說你想在div中。我不明白這個問題。 – Ariel
responseText在html中打印,但我想在div'testdiv'的innerHTML上打印responseText – Ankit
我也試過:function(responseText){alert('hiii - >'+ responseText); response = responseText; } \t alert('hello - >'+ response);第一個警報是打印reponseText,但不會將值複製到響應變量。所以,第二個警報是隻打印你好..我希望我解釋我的評論.. – Ankit