Click here to Skip to main content
13,902,840 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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>
 <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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190306.1 | Last Updated 24 Feb 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100