I have been trying to display json data in my jsp using struts and json. I am using jquery post to send the data to the action class, on success, it should fire a callback function is jquery post.But the callback is not fired.
I am unable to find the missing link in this.
Here are my codes..
My struts xml..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources"></constant>
<package name="default" extends="json-default">
<action name="some" class="action.Testing">
<result type="json">
<param name="root">displaying</param>
<param name="noCache">true</param>
</result>
</action>
</package>
</struts>
My jsp page is the following..
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<SCRIPT type="text/javascript" src="javascript/json.js"></SCRIPT>
<SCRIPT type="text/javascript" src="javascript/jquery.js"></SCRIPT>
<SCRIPT type="text/javascript" src="javascript/jquery.form.js"></SCRIPT>
<script type="text/javascript">
function somecallback(displaying){
var result = displaying.split(",");
var dataintext = result[0];
$('#sub').val(dataintext);
}
function test(){
var input = { "text" : "testing entry data",
"displaying" : "hello"
};
$.post('some.action',input,somecallback,"json");
}
$(function(){
$('#field').click(function(){
test();
return false;
});
</script>
</head>
<body>
<s:form method="post">
hello..
<s:submit id="field" value="click me too!!"></s:submit>
<s:textarea id="sub" name="tes" value="%{text}"></s:textarea>
<s:textarea id="second" name="tester"></s:textarea>
<div id="flag" style="height:100px;width:20px;">sfdsf</div>
<input type="text" id="hi" name="help" value="clicked here!!" />"
</s:form>
</body>
</html>
Any Suggestions and help greatly appreciated..
Thank you,
hemanth.
try changing the order you’re linking the scripts, jquery should be before you like any file using jquery
Also, don’t use onclick use: