使用ajax进行跨域调用 [英] Cross domain call with ajax

查看:110
本文介绍了使用ajax进行跨域调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ajax进行跨域调用。但是我收到错误或Uncaught SyntaxError:意外的令牌:

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>





我的尝试:



我检查我的响应是json,我正在进行jsonp调用,这就是我收到错误的原因。但如果我让它Json调用我有跨域错误。我已经在我的asp.net项目全局文件中添加了跨域标题。



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.

推荐答案

.ajax({
url:trgurl,
dataType:' JSONP'
类型: ' GET'
contentType:' application / json'
crossDomain: true
成功:函数(数据){
调试器;
alert(' 成功!' +数据);
},
错误:功能(数据){
调试器;
alert(' success!' + data);
},
完成: function (xhr,status){
debugger ;

}
});

< / script>
.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>





我的尝试:



我检查我的响应是json,我正在进行jsonp调用,这就是我收到错误的原因。但如果我让它Json调用我有跨域错误。我已经在我的asp.net项目全局文件中添加了跨域标题。



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.


之后我做了很多编码,并且知道只有你的代码必须是跨域但是目标域应该允许您进行跨域调用。请检查您的网址域是否允许您。
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.


这篇关于使用ajax进行跨域调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆