Not able to execute .load() using jQuery/Ajax from local file.
I am trying to access a servlet using jQuery Ajax via .load('http://host:port...) from a local HTML file in my c: directory. I can't get it to work. I am using jquery-1.9.1.js. Since it was not able to access the specific servlet ("http://host:port/servletName"), I tried to access www.google.com and no luck. Here is my code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load('http://www.google.com'),function(responseTxt,statusTxt,xhr){
if(statusTxt=="success")
alert("External content loaded successfully!");
if(statusTxt=="error")
alert("Error: "+xhr.status+": "+xhr.statusText);
});
});
});
</script>
</head>
<body>
<div id="div1"><h2>AJAX Change This Text</h2></div>
<button>Get Google Content</button>
</body>
</html>