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!
Your code is correct, however it is not possible to do a PUT request cross-domain unless the domain you are requesting data from is returning the proper CORS headers.