Struts2 Form submission with asynchronous jQuery ajax not working

I am trying to make a simple asynchronous Struts2 form submission using jQuery ajax feature. However, whatever i try, the jquery is not getting triggered.

Normal form submission is working smoothly but i need an asynchronous call which can fetch result from server without reloading page.

I have already tried normal forms, submission with JSON plugin and everything else that i could get my hands on from youtube, internet, stackoverflow etc. Please help, I am really unable to understand what i am doing wrong.

Using jQuery 1.3.2, Struts2: 2.3.14

P.S : I am using jQuery, AJAX call with Struts2 for first Time.

			$(document).ready(function() {
						type: 'POST',		
						data: {
							tslcText : $('#txtTslcDL').val(),
							userid : <% session.getAttribute("userid").toString(); %>,
							username : 'c'							
						url: 'updateTSLC.wht',
				        error: function(msg) {
				            if (msg.statusText != "OK") {
				                alert("Alert", "Error occured while retriving data.");
				       //Finish $.ajax()
				//Finish $('#updtTslcDL').click()
			//Finish $(document).ready()
<script src=""></script>
			<s:form id="frmUpdtTslcDL_s" theme="simple">&nbsp;&nbsp;&nbsp;&nbsp; 
			  	<s:textarea id="txtTslcDL" name="tslcText" rows="1" cols="7" value="2222:45"/>					
				<%-- <s:hidden id="userid" name="userid" value="%{#session.userid}"/>
				<s:hidden id="username" name="username" value="%{#session.username}"/>	 --%>	
				<s:submit id="updtTslcDL" name = "updtTslcDL" cssClass="button" value="Update" onclick="return false;"/>					
			<!-- <%-- 
			<form id="frmUpdtTslcDL" action="updateTSLC.wht" method="post">
					<textarea id="txtTslcDL" name="tslcText" rows="1" cols="7">123</textarea>
					<input type="hidden" id="iptuserid" name="userid" value=<% session.getAttribute("userid").toString(); %> />
					<input type="hidden" id="iptusername" name="username" value=<% session.getAttribute("username").toString(); %> />
					<input type="submit" id="iptupdtTslcDL" name = "updtTslcDL" class="button" value="Update"/>
			 --%> -->
			<div id="msgTslcDL"/>


<?xml version="1.0" encoding="UTF-8"?>
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    <constant name="struts.action.extension" value="wht" />
    <package name="default" namespace="/" extends="struts-default, json-default">
        <action name="validateAuthorization" class="test.ValidateUserAction" method="validateUser">
            <result name="success" type="redirect">/test.jsp</result>
            <result name="error" type="redirect">/error.jsp</result>

        <action name="updateTSLC" class="test.TestAction" method="updateTSLC">
            <result name="success" type="json">
                <param name="root">jsonResponse</param>
                <param name="location">/test.jsp</param>
            <result name="error">/error.jsp</result>

Action Class:

package test;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request = null;

    private String tslcText;
    private String userid;
    private String username;

    private Map<String, String> jsonResponse=new HashMap<String, String>();

    public String updateTSLC(){

        jsonResponse.put("out", "test: "+getTslcText()+", userid: "+getUserid()+", username: "+getUsername()+"_response");

        return SUCCESS;

    public String getTslcText() {
        return tslcText;

    public void setTslcText(String tslcText) {
        this.tslcText = tslcText;

    public String getUserid() {
        return userid;

    public void setUserid(String userid) {
        this.userid = userid;

    public String getUsername() {
        return username;

    public void setUsername(String username) {
        this.username = username;

    public Map<String, String> getJsonResponse() {
        return jsonResponse;

    public void setJsonResponse(Map<String, String> jsonResponse) {
        this.jsonResponse = jsonResponse;

    public void setServletRequest(HttpServletRequest inRequest) {
        request = inRequest;


Source: jquery

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.