Ajax struts2 iterator action





function isOpen(cid) {

	var stdIdObj = $("#stdId");

	var stdId = stdIdObj.val();
alert(cid+" "+stdId);
	$.get('/courseManage/s/openCourse?cid=' + cid + '&stdId=' + stdId, null,
			callback);

}
function callback(data) {
	alert(data);

	$("#result").html(data);
	$("#result").html("Open.....");

}

<html>
<head>
 <script type="text/javascript" src="js/isOpen.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
	</head>

	<body>
<td style="display: none">
								<input  type="hidden" value="<s:property value="cid"/>" />
						</td>


<s:iterator value="list">
<input type="hidden" type="text"  value="<s:property value="cid"/>"onclick="isOpen(this.value)"/>

</s:iterator>

	</body>
</html>

struts.xml





<package name="student" extends="struts-default" namespace="/s">

		<action name="opencourse" class="studentaction" method="stdBuyCourse">
			<result type="redirectAction">
			<param name="actionName">showstudentCourse</param>  
         	<param name="stdId">${stdId}</param>
         	</result>
			<result name="input">/index.jsp</result>
		</action>
  </package>

	  <package name="Struts2_AJAX" extends="json-default" namespace="/c">
       
       <action name="jsonOpen" class="studentaction" method="isOpen">
       <result type="redirectAction">showstudentCourse</result>
       
            <result type="json" />
        </action>            
    </package>





studentaction.java



public String isOpen(){
		courses = new ArrayList<Course>();

		type=1;
	
		
		courses.add(courseService.findCourseById(cid));
		
		std = stdService.findStdById(stdId);
		
		stdService.saveStdBuyCourse(courses, std, type);
		

		return SUCCESS;
	     
		  
	}