Click here to Skip to main content
16,020,182 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I am making cross domain call with ajax. But i am getting error or Uncaught SyntaxError: Unexpected token :
JavaScript
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
 <script type="text/javascript">
 debugger;
     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;

         }
     });

</script>


What I have tried:

I check that my response is json and i am making jsonp call that's why i get that error. But if i make it Json call i had cross domain error. I have already added the cross domain headers in my asp.net project globle files.
Posted
Updated 23-Feb-17 18:37pm
Comments
Sinisa Hajnal 11-Feb-16 3:06am    
You need to add Access-Control-Allow-Origin: * to header of the request.
Er. Puneet Goel 11-Feb-16 3:40am    
please tell me how to do that
Gopi Kishan Mariyala 11-Feb-16 23:02pm    
http://stackoverflow.com/questions/10093053/add-header-in-ajax-request-with-jquery

Can you please check above site. There are lot of solutions provided.

1 solution

I have done lot of coding afterwards and came to knew only your code has to be cross domain but the target domain should allow you to make that cross domain call. Please check if your url domain allows you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900