【发布时间】:2011-11-01 01:40:39
【问题描述】:
这个函数被绑定到一个按钮的点击事件:
function BlahBlahBlahWCFXML() {
varType = "POST";
varUrl = "http://123.123.123.123/NameOfService.svc/GetStuffById";
varData = '{"stuffId": "' + 12345678-abcd-9012-3456-abcdefghjkl' + '"}';
varContentType = "application/json; charset=utf-8";
varDataType = "xml";
varProcessData = true;
CallService();
}
然后那个函数调用这个函数:
//Generic function to call AXMX/WCF Service
function CallService()
{
$.ajax({
type : varType, //GET or POST or PUT or DELETE verb
url : varUrl, // Location of the service
cache : false,
data : varData, //Data sent to server
contentType : varContentType, // content type sent to server
dataType : varDataType, //Expected data format from server
processdata : varProcessData, //True or False
success : function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
当我尝试运行示例时,我在 Google Chrome 的开发者工具控制台窗口中得到以下信息:
加载资源失败:服务器响应状态为 400(错误请求) XMLHttpRequest 无法加载 http://123.123.123.123/NameOfService.svc/GetStuffById。 Access-Control-Allow-Origin 不允许 Origin null。
该服务运行良好,我目前正在通过网络表单和控制台应用程序调用它。 GetStuffById 是我要调用的方法。它接受一个字符串(在本例中为 GUID)作为参数并返回一个字符串。
该服务是 WCF 服务并配置为返回 SOAP 消息。我更喜欢 JSON,但那是前几天另一个问题的另一个问题。
有什么想法吗?谢谢!
更新 #1 - 我将 POST 更改为 GET。还是不行。
【问题讨论】:
标签: jquery wcf web-services .net-4.0