weixin_33682790 2016-10-10 15:23 采纳率: 0%
浏览 184

AJAX API PUT请求

Am I even close to success? I'm trying to use this block of code is jsfiddle to use a PUT request to the API, when using www.hurl.it with the same URL & XML, it succeeds, (woohoo!) but when I try it using this code I have no such luck.

Selecting "RUN" is jsfiddle yields nothing, as in nothing happens at all except the page flashing.

var url = 'https://api.example.com/v1.svc/results/modules/[moduleID]?apikey=[apikey]&source=[source]'

var xmldata = '<ModuleResult><CourseId>JJxblllJXcw1</CourseId><UserId>XaWpNO10m-M1</UserId><Score>100</Score> <Completed>false</Completed><UpdatedAt>2030-04-30T15:36:30</UpdatedAt><Note>JIL</Note></ModuleResult>'

$.ajax({
  url: url,
  type: 'PUT',
  contentType: 'application/XML',
  data: xmldata,
  success: function(data) {
    alert('Load was performed.');
  }
});

Any input would be greatly appreciated!

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33734785 2017-07-20 14:24
    关注

    The call wall being completed Cross Origin, the simple proxy prefilter shown below solved my issue.

    $.ajaxPrefilter( function (options) {
      if (options.crossDomain && jQuery.support.cors) {
        var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
        options.url = http + '//cors-anywhere.herokuapp.com/' + options.url;
      }
    });
    

    Note:
    A public proxy is not known for being extremely secure, whoever controls the proxy can see all of your data being pushed across it, so ensure the data is not sensitive if using a public proxy.

    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多