javascript - the requested resource does not support http method 'get'. Cross Domain -
i searching solution problem quite while. finding many answers question, cant figured out. here problem: trying send json file domain (its external firm web api cooperation firms), should send me json (i using mvc webapps), without using controller... first of had problem cross-domain, tried figured out editing web.config (see above).
<system.webserver> <httpprotocol> <customheaders> <remove name="x-powered-by" /> <add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-headers" value="content-type" /> <add name="access-control-allow-methods" value="get, post, put, delete, options" /> </customheaders> </httpprotocol>
this did not help. after using jsonp (see following jc code), problem solved. "the requested resource not support http method 'get'" - errormsg.
<script> $("#getprice").click(function () { $.support.cors = true; $.ajax({ type: "post", asnc: false, accept: "application/json", contenttype: "application/json", datatype: "jsonp", jsonpcallback: 'localjsonpcallback', url: "otherdomain.com" + "?callback=?", data: { models: [{ toolid: "", modelreference: "some model.xml", materialid: $("#materialid").val(), finishid: $("#finishid").val(), quantity: $("#quantity").val(), xdimmm: $("#xdimmm").val(), ydimmm: $("#ydimmm").val(), zdimmm: $("#zdimmm").val(), volumecm3: $("#volumecm3").val(), surfacecm2: $("#volumecm3").val() }], shipmentinfo: [{ countrycode: $("#countrycode").val(), statecode: "", city: $("#city").val(), zipcode: $("#zipcode").val() }], currency: $("#currency").val() }, xhrfields: { withcredentials: true }, crossdomain: true }) }) function localjsonpcallback(json) { if (!json.error) { alert("läuft"); console.log(json); } else { alert(json.message); } } </script>
while searching solution, find [httppost] info controller. problem here, not use controller buffer. directly send data view server , back.
ok got it! after not finding solution direct way, took controller intermediate... sending form data controller, has jsonresult action method. , in methode communicate via httpwebrequest external web api, , sending via httpreponse json data view.
oh me oh oh gosh...
Comments
Post a Comment