jquery 回调函数success不执行
js代码:varresult;functionclickButton(){varurl='judgeDevelopersName.action';varparams={n...
js代码:
var result;
function clickButton()
{
var url = 'judgeDevelopersName.action';
var params = {
name:$('#developers_name').attr('value')
};
jQuery.post(url, params, callbackFun, 'json');
}
function callbackFun(data)
{
alert(123);
result = data.resultcount;
alert(result);
if(result>0){
alert("客户名称重复!请重新输入");
}
}
action代码:
public class DevelopersAjax {
@Autowired
private DevelopersService developersService;//开发商对外服务
private String resultcount;
private String name;
/**
* 判断开发商名称是否重复
* @return
*/
public String judgeDevelopersName(){
Developers de = developersService.findDevelopersByName(name);
if(de != null){
resultcount = "1";
}else{
resultcount = "0";
}
return "success";
}
public DevelopersService getDevelopersService() {
return developersService;
}
public void setDevelopersService(DevelopersService developersService) {
this.developersService = developersService;
}
public String getResultcount() {
return resultcount;
}
public void setResultcount(String resultcount) {
this.resultcount = resultcount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
配置文件:
<?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>
<package name="check" extends="json-default" namespace="/">
<!-- 客户管理 ajax -->
<action name="judgeFileSize" method="judgeFileSize" class="com.commercial_pilot.ajax.SoftwareAjax">
<result type="json">
</result>
</action>
<action name="judgeDevelopersName" method="judgeDevelopersName" class="com.commercial_pilot.ajax.DevelopersAjax">
<result name="success" type="json">addDevelopersEdit.jsp</result>
</action>
</package>
</struts> 展开
var result;
function clickButton()
{
var url = 'judgeDevelopersName.action';
var params = {
name:$('#developers_name').attr('value')
};
jQuery.post(url, params, callbackFun, 'json');
}
function callbackFun(data)
{
alert(123);
result = data.resultcount;
alert(result);
if(result>0){
alert("客户名称重复!请重新输入");
}
}
action代码:
public class DevelopersAjax {
@Autowired
private DevelopersService developersService;//开发商对外服务
private String resultcount;
private String name;
/**
* 判断开发商名称是否重复
* @return
*/
public String judgeDevelopersName(){
Developers de = developersService.findDevelopersByName(name);
if(de != null){
resultcount = "1";
}else{
resultcount = "0";
}
return "success";
}
public DevelopersService getDevelopersService() {
return developersService;
}
public void setDevelopersService(DevelopersService developersService) {
this.developersService = developersService;
}
public String getResultcount() {
return resultcount;
}
public void setResultcount(String resultcount) {
this.resultcount = resultcount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
配置文件:
<?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>
<package name="check" extends="json-default" namespace="/">
<!-- 客户管理 ajax -->
<action name="judgeFileSize" method="judgeFileSize" class="com.commercial_pilot.ajax.SoftwareAjax">
<result type="json">
</result>
</action>
<action name="judgeDevelopersName" method="judgeDevelopersName" class="com.commercial_pilot.ajax.DevelopersAjax">
<result name="success" type="json">addDevelopersEdit.jsp</result>
</action>
</package>
</struts> 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询