Spring struts 2和jquery ajax调用
我正在使用Spring3、struts 2和jquery-1.8.2.js开发web项目 这是我的jquery ajax调用Spring struts 2和jquery ajax调用,spring,jquery,struts2,struts2-jquery,Spring,Jquery,Struts2,Struts2 Jquery,我正在使用Spring3、struts 2和jquery-1.8.2.js开发web项目 这是我的jquery ajax调用 function(){ var data = {}; data['patientFETO.title'] = $('#idSelTitle').val().trim(); data['patientFETO.firstName'] = $('#idFirstName').val().trim(); data['patientFETO.l
function(){
var data = {};
data['patientFETO.title'] = $('#idSelTitle').val().trim();
data['patientFETO.firstName'] = $('#idFirstName').val().trim();
data['patientFETO.lastName'] = $('#idLastName').val().trim();
data['patientFETO.mobileNumber'] = $('#idMobileNumber').val().trim();
data['patientFETO.idNumber'] = $('#idIDNumber').val().trim();
data['patientFETO.gender'] = $('#idSelGender').val().trim();
data['patientFETO.age'] = $('#idAge').val().trim();
data['patientFETO.dob'] = $('#idDOB').val().trim();
$.ajax({url:'savePatientAction',
cache: false,
type:"POST",
data:data,
dataType: 'json',
error: function(XMLHttpRequest, textStatus, errorThrown){
alert('Error ' + textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
},
success: function(data){
alert('SUCCESS');
}
这是我的struts动作映射
<action name="savePatientAction" class="appointmentAction" method="doPatientSave">
<result name="success">/account/confirmation.jsp</result>
<exception-mapping result="success" exception="e"></exception-mapping>
</action>
”
第7764行
请告诉我解决这个问题的方法
谢谢请按照以下步骤操作:
1.struts.xml-您需要启用JSON结果类型
2.在动作映射中
在进行这些更改后,当您调用响应时,响应将是JSON类型,ajax调用可以处理该类型。ajax()应执行以下操作:error:function(jqXHR,textStatus,errorhorn)
,而不是error:function(XMLHttpRequest,textStatus,errorhorn)
,关于:
由于您使用的是jquery 1.8,您应该更改参数的名称
您的意思是/account/confirmation.jsp吗?我已经将此部分添加到struts.xml文件中,当结果类型为json时,不需要jsp-只需将其保留为空,但我想导航到此jsp页面。我的操作不需要t将任何值返回给veiw
A function to be called if the request fails.
The function receives three arguments:
The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object,
a string describing the type of error that occurred
and an optional exception object, if one occurred.