ajax请求多个ip,jQuery AJAX脚本来更改IP地址 - 崩溃多个浏览器

我有一个窗体配置为更改网络设备上的IP地址,它都运行良好。我遇到的问题是如何处理客户端上的IP地址更改。我掀起了一些jQuery的本质,等待看看新的IP是否可达,如果它是浏览器转发,如果它不是浏览器显示新的IP信息,并让用户知道他们可能需要改变他们网络配置重新回到框中。jQuery AJAX脚本来更改IP地址 - 崩溃多个浏览器

问题在于,偶尔此脚本意外地遇到调用.ajax的错误条件,然后浏览器无法再加载该框上的任何页面。如果您使用任何其他浏览器,则Web服务器仍然可以访问,因此它不是盒子本身的问题。如果关闭浏览器并重新加载它的页面,这使我相信有一个循环,但我似乎无法找到它。以下是我在客户端使用的内容。

$(function(){

var newIp;

var newSnm;

var newGw;

var ns1;

var ns2;

$("#updateip").click(function(){

newIp = $("#ipaddress").val();

newSnm = $("#subnetmask").val();

newGw = $("#gateway").val();

ns1 = $("#ns1").val();

ns2 = $("#ns2").val();

$status.dialog('open');

$.ajax({

type: "POST",

url: "setuphandler.php",

data: { updateip : "false", ipaddress : newIp , subnetmask : newSnm, gateway : newGw, ns1 : ns1, ns2 : ns2},

timeout: 10000, //If the post doesnt finish in under 10 seconds this will force an error event

success: //This will fire if the IP was not changed by the post

function(xhr, data){

$status.dialog('close');

},

error: //This will fire if the IP address has been changed by the post

function(){

checkNewURL();

}

});

});

//Function to forward the browser if the new IP is reachable, if not alert the user and display the new settings to them

function checkNewURL(){

$.ajax({

type: "GET",

timeout: 700,

cache: false,

url: 'http://' + newIp,

error: //if the new ip is not reachable, display new connection info to the user

function(){

$status.dialog("option", "title", "Error");

$status.dialog("option", "height", 300);

$status.html(" \

\


\

Unable to contact new IP address. \


\

You may need to change settings on your local machine in order to communicate with this address. \


\

IP Address - " + newIp + "\

Subnet Mask - " + newSnm + "\

Gateway - " + newGw + "\

\

");

},

success: //If the new ip is reachable, auto-forward the user

function(){

$status.html("Redirecting...");

redirectUrl = 'http://' + newIp + '/setup.php'

setTimeout("window.location=redirectUrl", 2000);

}

});

}

$status.dialog({

modal: true,

height: 225,

width: 350,

title: 'Applying Changes',

autoOpen: false,

draggable: false,

resizable: false,

closeOnEscape: false,

open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值