Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax with Spring MVC not working
    primarykey
    data
    text
    <p>This is my jsp from where I try to inser the user</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Add Users using ajax&lt;/title&gt; &lt;script src="/Spring3MVC/js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function doAjaxPost() { // get the form values var firstName = $('#firstName').val(); var lastName = $('#lastName').val(); $.ajax({ type: "POST", url: "/insert", data: "firstName=" + firstName + "&amp;lastName=" + lastName, success: function(response) { // we have the response $('#info').html(response); $('#firstName').val(''); $('#lastName').val(''); }, error: function(e) { alert('Error: ' + e); } }); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Add Person&lt;/h1&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;First Name : &lt;/td&gt;&lt;td&gt; &lt;input type="text" id="firstName" name="firstName" /&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Last Name : &lt;/td&gt;&lt;td&gt; &lt;input type="text" id="lastName" name="lastName" /&gt; &lt;br/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="button" value="Add Users" onclick="doAjaxPost()"&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan="2"&gt;&lt;div id="info" style="color: green;"&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;a href="/SpringMVC/search"&gt;Show All Users&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And this is my controller code</p> <pre><code>@RequestMapping(value="/insert", method = RequestMethod.POST) public String insertPerson(ModelMap model, HttpServletRequest request, HttpServletResponse response, @RequestParam("firstName") String firstName, @RequestParam("lastName") String lastName ) { personDao.savePerson(firstName,lastName); model.addAttribute("nameAdded", firstName+" "+lastName); return "personAdded"; } </code></pre> <p>When I click the 'Add Users' button, nothing happens. Can anyone please help me in fixing this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload