我试图理解为什么这个 ajax 调用不起作用
$.ajax({
type: 'GET',
url: "http://localhost:8732/Design_Time_Addresses/InMotionGIT_NT.Address.Service/AddressService/json/capitalize",
data: { streetAddress : JSON.stringify(streetAddress) , consumer : JSON.stringify(consumer)} ,
datatype: "jsonp",
success: function (data) {
$('body').append('<div>'+data.IDblah+' '+ data.prueba+'</div>');
alert(data.IDblah);
}
接收数据的服务正确接收并且响应正确。为什么我做错了?
我尝试将此属性添加到名为的 ajax 中,但没有成功crossDomain : true
[OperationContract()]
[WebInvoke(Method="GET", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json)]
public string Capitalize(StreetAddress streetAddress,ConsumerInformation consumer)
我遇到的错误很常见
XMLHttpRequest cannot load Origin http://localhost:50816 is not allowed by Access-Control-Allow-Origin.
UPDATE
我尝试通过在我的配置中添加配置来将标头添加到响应中App.config
文件但没有成功
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>