如何使用jQuery / AJAX来填充在Spring表单实体对象的值?表单、如何使用、实体、对象

2023-09-10 17:51:01 作者:潴潴狭

我有弹簧形式

<form:form method="POST" action="/HelloWeb/addStudent" id="myForm">
   <table>
    <tr>
        <td><form:label path="name">Name</form:label></td>
        <td><form:input path="name" /></td>
    </tr>
    <tr>
        <td><form:label path="age">Age</form:label></td>
        <td><form:input path="age" /></td>
    </tr>
    <tr>
        <td><form:label path="id">id</form:label></td>
        <td><form:input path="id" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Submit"/>
        </td>
    </tr>
</table>  
</form:form>

我可以提交此表使用到控制器

i can submit this form to controller using

$.post('{controller path}', $('#myForm').serialize());

现在我想使用jQuery来填充实体对象/的这种形式和对象将从控制器返回阿贾克斯。

now i want to populate entity object using jquery/Ajax on the this form and object will be returned from controller.

亲切指导我?

下面是控制器,它调用新的一页,在填充表单对象的数据...

here is controller that call new page and populate object data on form...

@RequestMapping(value = "/addStudent", method = RequestMethod.POST) 
public ModelAndView addStudent(@ModelAttribute("SpringWeb")Student student, ModelMap model)
{ 
Student stud =new Student(); 
//here will be my code to use student object.... 
return new ModelAndView("ViewStudent", "SpringWeb",stud); 
} 

但此法加载,而不是调用新的,我想这样做的逻辑同一页上新的一页......

but this method load new page ...instead of calling new i want do this logic on same page

推荐答案

的形式:标签是PTED在服务器端跨$ P $,并定期生成的HTML标签在客户端。因为jQuery的只运行在客户端,它不会能够找到使用形式的东西:标签。尝试运行网页和查看HTML源代码,然后基于你jQuery选择上你所看到的在那里。

The form: tags are interpreted on the server side, and generate regular HTML tags on the client side. Since jQuery is only running on the client side, it won't be able to find things using the form: tags. Try running the page and viewing the HTML source, then base your jQuery selectors on what you see there.

 
精彩推荐
图片推荐