![](/img/trans.png)
[英]Calling WCF Service Using jquery Ajax failed with bad request response
[英]Calling WCF Service from JavaScript using AJAX through JQuery
我正在尝试通过JavaScript调用位于本地的WCF服务。 这是WCF服务的示例。
public string GetMarkers()
{
List<Marker> lstMarkers = new MarkerMgr().GetMarkers().ToList();
List<Marker> lstMark = new List<Marker>();
foreach (Marker m in lstMarkers)
{
Marker marker = new Web_Service.Marker();
marker.Id = m.Id;
marker.Latitude = m.Latitude;
marker.Longitude = m.Longitude;
marker.Title = m.Title;
marker.Description = m.Description;
marker.Icon = m.Icon;
lstMark.Add(marker);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = Int32.MaxValue;
return jss.Serialize(lstMark);
}
这就是我用来调用WCF服务的函数。
function getMarkers() {
var markers = null;
$.ajax({
async: true,
type: "GET",
url: "http://localhost:61892/Service.svc/GetMarkers", // the URL of the controller action method
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (result) {
alert(result);
markers = result;
},
error: function (req, status, error) {
alert(error);
}
});
return markers;
}
我尝试了许多不同的方法来解决此问题,但没有成功。 根据我所做的所有研究,我认为这与本地主机有关。 有人有主意吗? 非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.