Ohne weitere Umschweife poste ich einfach den Code für Sie. Der konkrete Inhalt lautet wie folgt:
// js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <script type= "text/javascript" >
function myBtn_f() {
var cnt = $( '#myCnt' ).val();
syncAjax( 'myAjax.html' , {
'cnt' : cnt
}, function (result) {
if (100 == result.statusCode) {
var data = result.lst;
var $d = $( '#myDiv' );
alert( "[" + data + "]" );
for ( var i = 0; i < data.length; i++) {
var input1 = $( "<input type='text' name='input1' />" );
input1.attr( 'value' , data[i]);
$d .append(input1);
}
} else {
alert( "error" );
}
});
}
function syncAjax(myUrl, myData, sufn) {
$.ajax({
url : myUrl,
data : myData,
type : 'post' ,
dataType : 'json' ,
cache : false,
async : false,
success : function (result) {
if (result.statusCode == 200) {
alert( "会话超时,请重新登录!" );
window.location.href = "index.jsp" ;
} else {
if (sufn)
sufn(result);
}
},
error : function (msg) {
alert( "error:" + msg);
}
});
};
</script>
|
Nach dem Login kopieren
//html
1 2 3 4 5 | <tr>
<td><input type= "text" id= "myCnt" /></td>
<td><div id= "myDiv" ></div></td>
</tr>
<input id= "myBtn" type= "button" value= "create" onclick= "myBtn_f()" />
|
Nach dem Login kopieren
//Backstage
1 2 3 4 5 6 7 8 9 10 11 12 13 | @RequestMapping( "myAjax" )
@ResponseBody
public String myAjax(
@RequestParam(defaultValue = "0" , required = false) int cnt) {
List<String> lst = new ArrayList<String>();
for (int i = 0; i < cnt; i++) {
lst.add( "no:" + i);
}
JSONObject result = new JSONObject();
result.put( "statusCode" , 100);
result.put( "lst" , lst);
return result.toString();
}
|
Nach dem Login kopieren
Dies ist das Ende aller Einführungen zur jQuery-Ajax-Anfrage zur Rückgabe von Listendaten und zur dynamischen Generierung von Eingabe-Tags sowie zur Zuweisung der Listendaten zu den Eingabe-Tags. Ich hoffe, dass dies für alle hilfreich ist!