0

Spring3、struts 2、jquery 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.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>

実行すると SyntaxError: JSON.parse: unexpected character " http://localhost:8080/ML/resources/js/jquery-1.8.2.js " 行 7764 が表示されます

この問題を解決する方法を教えてください ありがとう

4

2 に答える 2

0

次の手順に従います。1。struts.xml-JSON結果タイプを有効にする必要があります。2。アクションマッピングで、

これらの変更を行った後、呼び出すと、応答はJSONタイプになり、ajax呼び出しで処理できます。

于 2012-11-22T05:59:40.570 に答える
0

関数$.ajax()はこれを行う必要があります:error: function(jqXHR, textStatus, errorThrown)ではなくerror: function(XMLHttpRequest, textStatus, errorThrown)DOCUMENTに関して:

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. 

使用しているのでjquery 1.8, you should change the name of the parameter

于 2012-11-22T15:58:04.927 に答える