使用ajax进行跨域调用

编程入门 行业动态 更新时间:2024-10-11 23:26:22
本文介绍了使用ajax进行跨域调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

<script src="code.jquery/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 = "stageserv.interswitchng/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项目全局文件中添加了跨域标题。

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 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项目全局文件中添加了跨域标题。

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 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进行跨域调用

本文发布于:2023-11-28 12:42:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!