我在javascript的for循环中有10个不同的端口号,wcf服务托管在列出的10个端口中的一个端口号上。
有没有什么方法可以使用循环来检查,在使用ajax json的javascript中,我的服务响应在哪个端口号上没有任何错误。
下面是我的示例代码,但我想检查10个不同的端口号:
<script type = "text/javascript">
$("#search").live("click", function ()
{
var link = document.createElement('a');
link.setAttribute('href', 'http://localhost:55154/Services/Service.svc/GetCustomers');
alert(link.port);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: 'http://localhost:55154/Services/Service.svc/GetCustomers',
data: '{"prefix": "' + $("#prefix").val() + '"}',
processData: false,
dataType: "json",
success: function (response)
{
alert(response);
//var customers = eval(response.d);
//var html = "";
//$.each(customers, function () {
// html += "<span>Name: " + this.Name + " Id: " + this.Id + "</span><br />";
//});
//$("#results").html(html == "" ? "No results" : html);
},
error: function (a, b, c) {
alert(a.responseText);
}
});
});
</script>发布于 2015-03-04 02:10:11
执行循环并"pinging“wcf服务以检测它所在的位置并不是一个好主意。我建议你定义一个静态的WCF端口号。
单击您的WCF属性,然后单击项目菜单"Web“并配置选项”将服务器设置应用于所有用户(存储在项目文件中)“,因此标记选项”使用Visual Studio Development Server“并指定端口号。
https://stackoverflow.com/questions/28838656
复制相似问题