这是我写的用于获取ajax响应的脚本。
<script>
$( document ).ready(function()
{
$("#log").click(function(){
alert('hellow');
$.ajax({
url: "http://1xx.1xx.0.1xx:8081/script.login",
type: "GET",
data: { 'page':'create_user', 'access':'user','username':'user', 'password':'user'},
dataType: "html"
}).done(function(resp) {
console.log(resp);
var $response = $(resp);
});
});
})
</script>
这就是ajax响应体的样子。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta http-equiv="refresh" content="900" >
<title>Toronto Raptors</title>
<link href="Html/Panel/ControlPanelStyle.css" rel="stylesheet" type="text/css">
<!--THIS WILL SUPPRESS ALL ERROR POPUPS-->
<script type="text/javascript">
<!--
var debugMode = false; //turns on error messages for windows and grids ->false = production build
//Hide all window errors
if(debugMode == true){
function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;
}
//-->
</script>
<style type="text/css">
body {
margin: 0px;
padding: 0px;
position: absolute;
width: 100%;
height: 100%;
background: #244A77;
}
a img {
text-decoration: none;
border: 0 none;
}
Html, body {
Overflow:hidden;
}
font.text {
visibility:visible;
}
#pageContainer{
width: 100%;
height: 100%;
background: 244A77; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#244A77', endColorstr='#7DA7D9'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(244A77), to(7DA7D9)); /* for webkit browsers */
background: -moz-linear-gradient(top, #244A77, #7DA7D9); /* for firefox 3.6+ */
}
/*CSS for resizing counter Widgets*/
div#counter2containercontainer {position:absolute; width:100%; height:100%; margin: 0px auto; text-align:center; overflow:hidden; text-align: center; }
div.counter2container {position: relative; overflow: hidden; margin: 0px auto; border: none; font-family: Verdana, Geneva, Tahoma, sans-serif; font-weight: bold; text-align:center; vertical-align:middle; z-index: 4; width: 100%; height: 100%;}
div#counter5containercontainer {position:absolute; width:100%; height:100%; margin: 0px auto; text-align:center; overflow:hidden; text-align: center; }
div.counter5container {position: relative; overflow: hidden; margin: 0px auto; border: none; font-family: Verdana, Geneva, Tahoma, sans-serif; font-weight: bold; text-align:center; vertical-align:middle; z-index: 4; width: 100%; height: 100%;}
div#counter10containercontainer {position:absolute; width:100%; height:100%; margin: 0px auto; text-align:center; overflow:hidden; text-align: center; }
div.counter10container {position: relative; overflow: hidden; margin: 0px auto; border: none; font-family: Verdana, Geneva, Tahoma, sans-serif; font-weight: bold; text-align:center; vertical-align:middle; z-index: 4; width: 100%; height: 100%;}
div#counter11containercontainer {position:absolute; width:100%; height:100%; margin: 0px auto; text-align:center; overflow:hidden; text-align: center; }
div.counter11container {position: relative; overflow: hidden; margin: 0px auto; border: none; font-family: Verdana, Geneva, Tahoma, sans-serif; font-weight: bold; text-align:center; vertical-align:middle; z-index: 4; width: 100%; height: 100%;}
</style >
<!-- general window handling -->
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxWindows/codebase/dhtmlxwindows.css" />
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxWindows/codebase/skins/dhtmlxwindows_dhx_skyblue.css" />
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxWindows/codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxWindows/codebase/dhtmlxwindows.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxWindows/codebase/dhtmlxcontainer.js"></script>
<!--Tree - Used for Triggers -->
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxTree/codebase/dhtmlxtree.css" />
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxTree/codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxTree/codebase/dhtmlxtree.js"></script>
<!--acordian Used for Triggers and Healtcare -->
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxAccordion/codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxAccordion/codebase/dhtmlxaccordion.js"></script>
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxAccordion/codebase/skins/dhtmlxaccordion_dhx_skyblue.css" />
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxAccordion/codebase/dhtmlxcontainer.js"></script>
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxMenu/codebase/skins/dhtmlxmenu_dhx_skyblue.css" />
<script src="../../dhtmxSuite/dhtmlxMenu/codebase/dhtmlxcommon.js"></script>
<script src="../../dhtmxSuite/dhtmlxMenu/codebase/dhtmlxmenu.js"></script>
<!--Other Header Files Required-->
<!--JAVASCRIPT to autore-size counter widgets-->
<script type="text/javascript">
//$(document).ready(function() {
function divresize(counterName) {
//alert("RIZSE1");
var containerName = '.' + counterName + 'container'
var secondContainer = '#' + counterName + "containercontainer";
var contentwidth = $(secondContainer ).width();
var contentheight = $(secondContainer ).height();
$(containerName).css('width',contentwidth )
$(containerName).css('height',contentheight );
//Better ReSize Attempt...
//Determine Character Width
/*var elem = document.getElementById(counterName +"_Value");
var currentText = elem.innerHTML;
var widthMultiplier = 1;
if(currentText.length > 1){
widthMultiplier = (currentText.length);
contentwidth = contentwidth / (widthMultiplier);
}*/
//Make the size the same as the smaller of the two dimensions
if(contentwidth < contentheight){ $('#' + counterName+ '_Value.text').css('font-size',contentwidth / (1.3)); }
else{ $('#' + counterName+ '_Value.text').css('font-size',contentheight / (1.3)); }
//alert("RIZSE");
}
</script>
<!-- dhtmlxGrid -->
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxGrid/codebase/ext/dhtmlxgrid_ssc.js"></script>
<link rel="STYLESHEET" type="text/css" href="../../dhtmxSuite/dhtmlxGrid/codebase/dhtmlxgrid.css">
<link rel="stylesheet" type="text/css" href="../../dhtmxSuite/dhtmlxGrid/codebase/skins/dhtmlxgrid_dhx_skyblue.css">
<!--dhtmlxCharts Required-->
<link rel="STYLESHEET" type="text/css" href="../../dhtmxSuite/dhtmlxChart/codebase/dhtmlxchart.css">
<script type="text/javascript" src="../../dhtmxSuite/dhtmlxChart/codebase/dhtmlxchart.js"></script>
<!--Javascript For Speedo and/or Counter Required-->
<script type="text/javascript" src="WidgetFiles/jquery.speedometer-1.0.4/jquery-1.4.min.js"></script>
<script type="text/javascript" src="WidgetFiles/jquery.speedometer-1.0.4/jquery.speedometer.js"></script>
<script type="text/javascript" src="WidgetFiles/jquery.speedometer-1.0.4/jquery.jqcanvas-modified.js"></script>
<script type="text/javascript" src="WidgetFiles/jquery.speedometer-1.0.4/excanvas-modified.js"></script>
</head>
<!--<body onload="doOnLoad();" style="background-image: url('../../dhtmxSuite/images/BannerTileBackground.gif'); background-repeat: repeat-x; background-color: #87AEC5;" >-->
<body onload="doOnLoad();" >
<div id="pageContainer">
<div id="counter2_div">
<div id="counter2containercontainer">
<div class="counter2container"><font class="text" id="counter2_Value"></font></div>
</div>
</div>
<div id="counter5_div">
<div id="counter5containercontainer">
<div class="counter5container"><font class="text" id="counter5_Value"></font></div>
</div>
</div>
<div id="counter10_div">
<div id="counter10containercontainer">
<div class="counter10container"><font class="text" id="counter10_Value"></font></div>
</div>
</div>
<div id="counter11_div">
<div id="counter11containercontainer">
<div class="counter11container"><font class="text" id="counter11_Value"></font></div>
</div>
</div>
<div id="pie_medium6_div" style="width:100%;height:100%;position:absolute"></div>
<div id="speedometer4_div" style="width:100%;height:100%;position:relative;left:0px;top:0px">0</div>
<script type="text/javascript">$(function(){ $('#speedometer4_div').speedometer(); }); </script>
<!--<div id="winVP" style="position: relative; height: 100%; margin: 0px;"></div>-->
<div id="triggersActive" style="width:100%;height:100%;"></div>
<div id="triggersHistory" style="width:100%;height:100%;"></div>
<div id="triggerBox" style="width:100%;height:100%;"></div>
<div id="pageFooter">Powered By Raptors</div>
</div>
</body>
<script type="text/javascript">
var dhxWins;
var dhxAccord;
var menu;
var w999;
var triggers;
var showWidgets;
var tree;
//Globals needed for banner messages
var marqueeQueue = [""];
var lastMessage = "";
var lastTrigger = "";
var lastFiringTriggerList = "";
var marqueeCounter = 0;
var marqueeIndex = 0;
//Globals needed for initial start positions if null
var curTopPos = 27;
var curLeftPos = 0;
var curBottomPos = 0;
var windowDim = getBrowserDimensions();
var maxWidth = windowDim.split(',')[0];
var maxHeight = windowDim.split(',')[1];
var initialLoadMode = true;
var warningBorderSytle = "solid 5px #FFFF00";
var urgentBorderSytle = "solid 7px #FFA500";
var criticalBorderSytle = "solid 10px #FF0000";
function doOnLoad() {
//Ignore chart Errors
if(debugMode == false){
dhtmlxError.catchError("LoadXML",function(a,b,data){ });
}
//Create a viewport and attach to existing div
dhxWins = new dhtmlXWindows();
//dhxWins.enableAutoViewport(false);
//dhxWins.attachViewportTo("winVP");
//Handle moving and resizing widgets... save to cookie
dhxWins.attachEvent("onMoveFinish", function(win){ setWindowStatusCookie(win,1); });
dhxWins.attachEvent("onResizeFinish", function(win){ setWindowStatusCookie(win,1); });
dhxWins.attachEvent("onFocus", function(win){ updateZIndex(win); });
//dhxWins.attachEvent("onClose", function(win){ setWindowStatusCookie(win,0); });
dhxWins.setImagePath("dhtmxSuite/dhtmlxWindows/codebase/imgs/");
dhxWins.attachEvent("onClose", function(win){ win.hide(); });
//ShowWidgets Window
showWidgets = dhxWins.createWindow("showWidgets", 0, 30, 250, 600);
showWidgets.setText("Add Widget");
tree = showWidgets.attachTree();
tree.setSkin('dhx_skyblue');
tree.setImagePath("../../dhtmxSuite/dhtmlxTree/codebase/imgs/csh_bluefolders/");
tree.setOnCheckHandler(widgetTree_oncheck);
tree.enableCheckBoxes(true,true);
tree.deleteChildItems(0);
tree.insertNewChild(0, 'w2', "Raptors are back");
tree.insertNewChild(0, 'w5', "Celtics is never the same");
tree.insertNewChild(0, 'w10', "lakers are up");
tree.insertNewChild(0, 'w11', "Heat is going down");
tree.insertNewChild(0, 'w1', "Leafs are back");
</script>
我很感兴趣解析它所说的最底层部分:
tree.insertNewChild(0,'w2',“猛龙回来了”);
从此我想解析==&gt;猛龙回来了
任何人都可以提供一些指导或线索或帮助我如何做到这一点?我被困在这2天了。我对Web开发一般都很陌生,所以如果这是一个措辞不好的问题我会道歉。
答案 0 :(得分:0)
如果您需要以HTML格式接受结果,那么这样的事情应该有效:
$.ajax({
url: "http://1xx.1xx.0.1xx:8081/script.login",
type: "GET",
data: { 'page':'create_user', 'access':'user','username':'user', 'password':'user'},
dataType: "html",
success: function (html) {
alert(/tree.insertNewChild\([^"]*"([^"]*?)"\);/g.exec(html)[1]);
}
});
以下是关于jFiddle的示例: http://jsfiddle.net/hcrM8/16/