0

In my local m/c I am trying to validate the User by passing his details to a Cross-domain Url. On browser Console Log I get error "Uncaught SyntaxError: Unexpected token :" and when i click on it I get {"response": "PASS"}.

jQuery.ajax({
    type: 'GET',
    dataType: 'JSONP',
    url: 'https://my.site.com/validation.xml',
    jsonpCallback: 'callback',
    jsonp: false,
    data: {
        accountnumber: ActNumber                
    },
    timeout: 60000,
    success: accountValidationResponse,
    error: accountValidationError
});
https://my.site.com/validation.xml'?callback=jQuery22409542193305264031_1483533842731&accountnumber=12345678&_=1483533842732

Changing the dataType to json gives me this error:

No "Access-Control-Allow-Origin' header is present on the requested resource

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Shailesh
  • 554
  • 1
  • 6
  • 29
  • 1
    Normally this occurs when people are trying to get around a CORS issue so just set JSONP as the response type. Are you 100% sure the response is in JSONP format? It's not interchangeable with JSON. – Rory McCrossan Jan 04 '17 at 13:59
  • calling an XML resource and you expect to get JSONP back? Seems strange. You can not just request JSONP and get it to return, the service needs to understand that and handle it. – epascarello Jan 04 '17 at 14:00
  • I added a real URL in Comments , does it wrong – Shailesh Jan 04 '17 at 14:05
  • I copied the Code from Other Site and implication in local. In the Original site this code having dataType: 'JSON' – Shailesh Jan 04 '17 at 14:08
  • That's not JSONP - that's JSON. Change `dataType: 'json'` and remove `jsonpCallback` and `jsonp` parameters. – Rory McCrossan Jan 04 '17 at 14:18
  • Then i get "Access-Control-Allow-Origin' header is present on the requested resource. Origin – Shailesh Jan 04 '17 at 14:23
  • That's what I suspected in my first comment. This means that the domain you're calling does not include CORS headers in the response. In turn, you cannot make a request to the domain from JS code - you'll have to do it server side. See the question I marked as duplicate for more information – Rory McCrossan Jan 04 '17 at 14:30

0 Answers0