我正在创建一个对WCF服务的简单Javascript调用,并且在脚本调用该服务之后,它将返回该调用的错误。通过Fiddler调用WCF服务虽然给了我正确的结果。所以我再次尝试运行Fiddler运行脚本来捕获数据包。似乎脚本没有将结果识别为有效结果,从而引发错误,因为Fiddler再次捕获了正确的结果。
一些参考文献:
IWorkflowService:
[ServiceContract]
public interface IWorkflowService
{
[OperationContract]
[WebGet(UriTemplate="GetWorkflowDetails?instanceId={instanceId}", ResponseFormat = WebMessageFormat.Json)]
WorkflowInstance GetWorkflowDetails(string instanceId);
}
[DataContract]
public class WorkflowInstance
{
//properties
[DataMember]
public string Result {get; set;}
}
WorkflowService.cs:
public class WorkflowService : IWorkflowService
{
public WorkflowInstance GetWorkflowDetails(string instanceId)
{
WorkflowInstance instance = new WorkflowInstance() { Result = instanceId };
return instance;
}
}
aspx页面上的脚本:
var args = getQueryVariable("instanceId");
var url = "http://localhost:56091/WorkflowService.svc/GetWorkflowDetails?instanceId="+args;
//alert(url);
$("textArea").append(url);
$.ajax({
type: "GET",
url: url,
success: function (result) {
alert(result);
},
error: function (error) {
alert("Error: " + error.responseText);
}
});
Fiddler的原始结果:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 10 Sep 2014 02:15:00 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 49
Cache-Control: private
Content-Type: application/json; charset=utf-8
Connection: Close
{"Result":"9b3f4bfb-27f0-4570-82ba-3719109bab76"}
答案 0 :(得分:0)
通过将数据类型写为application / json并尝试将json结果放入var res = result来尝试此操作 喜欢
var res=result
alert(res);