如何从jsp和action调用ajax [英] how to call ajax from jsp and action

查看:75
本文介绍了如何从jsp和action调用ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

& 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&regular = + ;
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 =

&lt;html>
    &lt;head>
&lt;title>Jsp for Student&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&regular=" + 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆