0

I am developing web project by using Spring3,struts 2 and jquery jquery-1.8.2.js.

this is my jquery ajax call

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');

           }

and this is my struts action mapping

<action name="savePatientAction" class="appointmentAction" method="doPatientSave">
        <result name="success">/account/confirmation.jsp</result>
        <exception-mapping result="success" exception="e"></exception-mapping>
    </action>

when i run it gives SyntaxError: JSON.parse: unexpected character "http://localhost:8080/ML/resources/js/jquery-1.8.2.js" Line 7764

Please give me idea to fix this issue Thanks

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Pradeep Gamage
  • 585
  • 4
  • 8
  • 21

2 Answers2

0

Follow these steps: 1. struts.xml - You need to enable JSON result type 2. In your action mapping,

After making these changes, when you invoke the response will be of JSON type, which the ajax call can handle

saasthasoft
  • 123
  • 8
0

The function $.ajax() should do this: error: function(jqXHR, textStatus, errorThrown), not error: function(XMLHttpRequest, textStatus, errorThrown), regards to the 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. 

Since you are using jquery 1.8, you should change the name of the parameter

Jaiwo99
  • 9,687
  • 3
  • 36
  • 53