gpt4 book ai didi

jquery 回调没有被触发

转载 作者:行者123 更新时间:2023-12-01 04:23:47 25 4
gpt4 key购买 nike

我一直在尝试使用struts和json在我的jsp中显示json数据。我正在使用 jquery post 将数据发送到操作类,成功后,它应该触发 jquery post 的回调函数。但是回调没有被触发。

我无法找到其中缺少的链接。

这是我的代码..

我的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>

我的jsp页面如下..

 <%@ 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>

非常感谢任何建议和帮助..

谢谢你,赫曼斯。

最佳答案

尝试更改链接脚本的顺序,jquery 应该位于使用 jquery 的任何文件之前

<SCRIPT type="text/javascript" src="javascript/jquery.js"></SCRIPT>
<SCRIPT type="text/javascript" src="javascript/json.js"></SCRIPT>
<SCRIPT type="text/javascript" src="javascript/jquery.form.js"></SCRIPT>

另外,不要使用 onclick 使用:

$('#field').click(function(){
test();
});

关于jquery 回调没有被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8208981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com