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="" type="text/javascript"></script>
 <script type="text/javascript">
     var prodID = "4220";
     var txRef = "d38e92010";
     var amt = "10000";
     var hasKey = "60e0fac58c36accabc393172d6546320ecf00628fbba3a4bb4f9ef72c51f1c11e0c677fd9de5f7b9e45e2336871617fa845b24a6c85d541fc5a59726537d0abf";
     var mackey = "199F6031F20C63C18E2DC6F9CBA7689137661A05ADD4114ED10F5AFB64BE625B6A9993A634F590B64887EEB93FCFECB513EF9DE1C0B53FA33D287221D75643AB";
     var trgurl = "" + prodID + "&transactionreference=" + txRef + "&amount=" + amt + "&hash=" + hasKey + "&mackey=" + mackey + "";

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



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 project globle files.
Updated 23-Feb-17 18:37pm
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

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

1 solution

Rate this: bad
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