Nonsense not to say, directly to everyone paste code, the specific content as follows:
Js
<script type= "Text/javascript" >
function Mybtn_f () {
var cnt = $ (' #myCnt '). Val ();
Syncajax (' myajax.html ', {
' cnt ': CNT
}, Function (result) {
if (= = = Result.statuscode) {
var data = Res Ult.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 = (=) {
alert ("Session timed out, please login again!") ");
Window.location.href = "index.jsp";
} else {
if (SUFN)
sufn (result);
}
,
error:function (msg) {
alert ("Error:" + msg);
}
});
};
</script>
Html
<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 ()"/ >
Background
@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");
Result.put ("LST", LST);
return result.tostring ();
}
About jquery Ajax request return list data dynamically generate input tag, and the list data assigned to the input tag all introduction to this end, I hope to help you!