0

I am making cross domain call with ajax. But i am getting error or Uncaught SyntaxError: Unexpected token :

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

 var prodID = "4220";
 var txRef = "d38e92010";
 var amt = "10000";
 var hasKey = "60e0fac58c36accabc393172d6546320ecf00628fbba3a4bb4f9ef72c51f1c11e0c677fd9de5f7b9e45e2336871617fa845b24a6c85d541fc5a59726537d0abf";
 var mackey = "199F6031F20C63C18E2DC6F9CBA7689137661A05ADD4114ED10F5AFB64BE625B6A9993A634F590B64887EEB93FCFECB513EF9DE1C0B53FA33D287221D75643AB";
 var trgurl = "https://stageserv.interswitchng.com/test_paydirect/api/v1/gettransaction.json?productid=" + prodID + "&transactionreference=" + txRef + "&amount=" + amt + "&hash=" + hasKey + "&mackey=" + mackey + "";


 $.ajax({
     url: trgurl,
     dataType: 'JSONP',
     type: 'GET',
     contentType: 'application/json',
     crossDomain: true,
     success: function (data) {
         debugger;
         alert('success!' + data);
     },
     error: function (data) {
         debugger;
         alert('success!' + data);
     },
     complete: function (xhr, status) {
         debugger;

     }
 });

I had also added the Allow-Cross_origin header to my request. In case i remove JSONP it get cross domain error.

Puneet Goel
  • 99
  • 1
  • 9
  • it looks like duplicate but is not. Its asp.net based and i tried all solutionover there and target site is not under my control. So much limitation. – Puneet Goel Feb 11 '16 at 06:24
  • Please provide the full error message –  Feb 11 '16 at 06:24
  • Just add this code to simple html page header and you will get details. Comment size limit doesn't allow me to add full error. – Puneet Goel Feb 11 '16 at 06:34
  • This isn't a forum! You should edit your question. –  Feb 11 '16 at 15:53

1 Answers1

0

I googled the things and tried adding headers. But finally i get to know a service to be accessible cross domain is not totally depend upon how you call it, but also on hosting. I found the service i was calling is not allowed to access cross domain, it was problem at host. Thanks everyone for support.

Puneet Goel
  • 99
  • 1
  • 9