简体   繁体   中英

AJAX api PUT request

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM