简体   繁体   中英

JSON PUT Request Error

I am trying to use to a PUT call to a API using JSON. I am using jQuery and from what I can tell my code looks right:

<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            url: 'https://app.clickdimensions.com/Service.svc/v1/account/accountIdHere/capture',
            type: 'PUT',
            data: { 'reg_FirstName': 'First',
                    'reg_LastName': 'Last',
                    'reg_Phone': '123-342-1211',
                    'reg_Email': 'email@email.com',
                    'reg_Company': 'My Company',
                    'reg_Address1': '123 Traffic Lane',
                    'reg_Address2': '',
                    'reg_City': 'Atlanta',
                    'reg_State': 'GA',
                    'reg_Zip': '12232',
                    'reg_Country': 'United States'  
            },
            success: function() { alert('PUT completed'); }
        });
    });
</script>

But when I run it I get the following error:

XMLHttpRequest cannot load https://app.clickdimensions.com/Service.svc/v1/account/accountIdHere/capture. Origin http://localhost:65116 is not allowed by Access-Control-Allow-Origin.

I've looked everywhere and tried about everything I can find to no avail. So I'm thinking my code might be wrong to do a JSON PUT call. Does my code look wrong? If so how could I fix it. If not, any idea on that error?

Thanks!

您的代码是正确的,但是除非您请求数据的域返回正确的CORS标头,否则无法跨域执行PUT请求。

Your jQuery looks good. The problem lies in Origin http://localhost:65116 is not allowed by Access-Control-Allow-Origin.

This suggests Cross-Domain resource loading, which is verboten in most situations. If you have control over https://app.clickdimensions.com/Service.svc/v1/account/accountIdHere/capture you can modify it to allow such requests from specific domains, or you could use JSONP instead of JSON to do cross-domain requests, although I'm unsure of your success with an HTTP PUT in such an instance. JSONP, to my knowledge, needs to be an HTTP GET.

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