none
AJAX Call to WCF REST Service RRS feed

  • Question

  • Hi Everyone,

    I Created a WCF REST service, Its works fine in Telerik Fiddler, giving response as expected. When I call the same URL from Jquery Ajax with the following sample Jquery  code, It fires error event of Ajax call and gives response like readyState: 4, Status: 200, Message: Success in the first parameter and second parameter has some text like "parseerror".  Please find below sample response format from my service. I could not find that where the problem is. With fiddler its working fine and giving response like below "Sample Response" but not with AJAX Call. Could you find below web.config changes of REST service.

    Sample Jquery Ajax code

    $.ajax({
                 type: "GET",
                 dataType: "jsonp",
                 url: "https://bbbbbbbb/yyyyy/zzzzzzzz.svc/GetAPGoldServiceResponse?LicenceNumber=W35125910545606&Password=Password9",
                 success: function(data){       
                    alert(data);
                 },
           error: function(e,e1,e2){ 
    debugger;
                 alert('Error121212: ' + e); 
               } 
             });

    Sample Response:

    {
    "Drivers":{
    "0":{
    "firstName": "NICOLE",
    "lastName": "WHITE",
    "dateOfbirthYear": "1954",
    "dateOfbirthMonth": "6",
    "dateOfbirthDay": "6",
    "gender": "F",
    "maritalStatus" : " UNAVAILABLE ",
    "postalCode": "M2R1K1",
    "driverTrainingInd" : "false",
    "yearsWithCurrentInsurer" : "5",
    "lossesYearsInd" : "2",
    "date1" : "04",
    "retiredInd" : "false"
    },
    "1":{
    "firstName": "STEPHEN",
    "lastName": "WHITE",
    "dateOfbirthYear": "1954",
    "dateOfbirthMonth": "5",
    "dateOfbirthDay": "5",
    "gender": "U",
    "maritalStatus" : "UNAVAILABLE",
    "relationshipToPolicyHolder" : "X1",
    "lossesYearsInd" : "false",
    "date1" : "Blank"
    }
    },
    "Vehicles":{
    "0":{
    "year" : "2000",
    "make" : "YAMAHA",
    "model" :{
    "value" : "Blank",
    "label" : "YSR80"
    },
    "principalDriver" : "0",
    "distanceWorkSchool" : "UNAVAILABLE",
    "annualKm" : "UNAVAILABLE",
    "businessKm" : "UNAVAILABLE",
    "otherAntiTheftDeviceIndicator" : "electronicAlarm"
    },
    "1":{
    "year" : "2002",
    "make" : "HONDA TRUCK/VAN",
    "model" :{
    "value" : "091403",
    "label" : "ODYSSEY EX-L"
    },
    "principalDriver" : "0",
    "distanceWorkSchool" : "UNAVAILABLE",
    "annualKm" : "UNAVAILABLE",
    "businessKm" : "UNAVAILABLE",
    "otherAntiTheftDeviceIndicator" : "electronicAlarm"
    }
    },
    "id" : "reference"
    }

    Web.Config Changes:

     <standardEndpoints>
         <webScriptEndpoint>
           <standardEndpoint crossDomainScriptAccessEnabled="true"></standardEndpoint>
         </webScriptEndpoint>
       </standardEndpoints>
     This node should be added as a child of the service  node (<system.serviceModel>).
      </serviceBehaviors>
         <endpointBehaviors>
           <behavior name="web">
             <webHttp/>
           </behavior>
         </endpointBehaviors>
     This node should be added as a child of the service behavior node (<behavior>).
     <bindings>
           <webHttpBinding>
             <binding crossDomainScriptAccessEnabled="true"></binding>
           </webHttpBinding>
         </bindings>

    This node should be added as a child of the service  node (<system.serviceModel>).


    Thursday, July 23, 2015 7:13 AM

Answers