如何从jsp和action调用ajax [英] how to call ajax from jsp and action
问题描述
& lt; html>
& lt; head>
& lt; title> Jsp 学生& lt; / title>
& lt; script type = text / javascript >
function getRegular(){
alert(document.getElementById(' lbl1')。 value );
value = document.getElementById(' lbl1 跨度>)的innerHTML。
request = getRequest();
url = StudentAction.do?method=select®ular = + 值;
request.onreadystatechange = handleResponse;
request.open( POST,url,真跨度>);
document.getElementById(' otherText')。 value = ;
document.getElementById(' otherText')。disabled = 真跨度>;
request.send( null );
}
函数showTextField(){
document.getElementById(' otherText')。disabled = false ;
}
函数showData( value ){
if (< span class =code-sdkkeyword> value != ' '){
alert( value );
request = getRequest();
request.onreadystatechange = handleResponse;
request.open( POST, StudentAction.do?method=select&other = + value ,
true );
request.send( null );
}
// document.getElementById('lbl2')。innerHTML = document
// .getElementById('stname')。value;
}
函数getRequest(){
if (window.ActiveXObject){
return ( new ActiveXObject(' Microsoft.XMLHTTP'跨度>));
} else if (window.XMLHttpRequest){
return ( new XMLHttpRequest());
} 其他 {
return 空跨度>;
}
}函数handleResponse(){
if (request.readyState == 4 ){
var datev = new Date();
var abc = request.responseText;
alert(abc);
document.getElementById(' lbl2')。innerHTML = abc;
// document.getElementById('datelbl')。innerHTML = new Date();
}
}
< / script>
< / head>
< body>
< input type =radioname =regularvalue =1önclick=getRegular()/>
NO
< label id =lbl1>
< c:out value =$ {StudentForm.regular}xmlns:c =#unknown> ;
< / label>
< input type =radioname =regularvalue =2 önclick=showTextField()/>
< input type =textname =otherid =otherText
$ b $bönblur=showData( this.value)disabled =disabled/>
< label id =lbl2>
$ 0
< / label>
< label>
< c:out value =$ {StudentForm.bankName}xmlns:c =#unknown>
< / label>
< label>
< c:out value =$ {StudentForm.service}xmlns:c =#unknown >
< / label>
< input type =hiddenname =bankNameid =bankIdvalue =< c:out value =$ {StudentForm.bankName}xmlns:c =#unknown>/>
< / body>
< / html>
{StudentForm.regular}xmlns:c =#unknown>
< / label>
< input type =radioname =regularvalue =2önclick=showTextField()/>
< input type =textname =otherid =otherText
$ b $bönblur=showData(this.value)disabled =disabled/ >
< label id =lbl2>
0 >
< / label>
< label>
< c:out value =
{StudentForm.bankName}xmlns:c =#unknown>
< / label>
< label>
< c:out value =
<html>
<head>
<title>Jsp for Student</title>
<script type="text/javascript">
function getRegular(){
alert(document.getElementById('lbl1').value);
value=document.getElementById('lbl1').innerHTML;
request = getRequest();
url="StudentAction.do?method=select®ular=" + value ;
request.onreadystatechange = handleResponse;
request.open("POST", url, true);
document.getElementById('otherText').value = "";
document.getElementById('otherText').disabled = true;
request.send(null);
}
function showTextField() {
document.getElementById('otherText').disabled = false;
}
function showData(value) {
if (value != '') {
alert(value);
request = getRequest();
request.onreadystatechange = handleResponse;
request.open("POST", "StudentAction.do?method=select&other=" + value,
true);
request.send(null);
}
//document.getElementById('lbl2').innerHTML = document
// .getElementById('stname').value;
}
function getRequest() {
if (window.ActiveXObject) {
return (new ActiveXObject('Microsoft.XMLHTTP'));
} else if (window.XMLHttpRequest) {
return (new XMLHttpRequest());
} else {
return null;
}
}function handleResponse() {
if (request.readyState == 4) {
var datev=new Date();
var abc=request.responseText;
alert(abc);
document.getElementById('lbl2').innerHTML =abc;
//document.getElementById('datelbl').innerHTML=new Date();
}
}
</script>
</head>
<body>
<input type="radio" name="regular" value="1" önclick="getRegular()" />
NO
<label id="lbl1">
<c:out value="${StudentForm.regular}" xmlns:c="#unknown">
</label>
<input type="radio" name="regular" value="2" önclick="showTextField()" />
<input type="text" name="other" id="otherText"
önblur="showData(this.value)" disabled="disabled" />
<label id="lbl2">
$0
</label>
<label>
<c:out value="${StudentForm.bankName}" xmlns:c="#unknown">
</label>
<label >
<c:out value="${StudentForm.service}" xmlns:c="#unknown">
</label>
<input type="hidden" name="bankName" id="bankId" value="<c:out value="${StudentForm.bankName}" xmlns:c="#unknown">"/>
</body>
</html>
{StudentForm.regular}" xmlns:c="#unknown">
</label>
<input type="radio" name="regular" value="2" önclick="showTextField()" />
<input type="text" name="other" id="otherText"
önblur="showData(this.value)" disabled="disabled" />
<label id="lbl2">
0
</label>
<label>
<c:out value="
{StudentForm.bankName}" xmlns:c="#unknown">
</label>
<label >
<c:out value="
这篇关于如何从jsp和action调用ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!