Eclipse JQuery 无法处理我简单的 Hello World 程序
Eclipse JQuery not working on my simple Hello World program
几天来我一直在努力 JQuery 开发一个简单的 hello world 程序。我的程序所做的是当我按下按钮时,它是否将 XMLHTTPRequest() 发送到 java servlet,并将 "Hey World" 更改为 "Hello World"。我是 JQuery 和 java 脚本的新手。我知道您的项目中需要有一个 jquery.js 文件,它目前位于我的 WebContent/WEB-INF/ 文件夹以及我的 JavaScript Resources 文件夹中。我正在使用 HTML 文件,唯一使用 JQuery 的行是 $("#here").html(this.responseText)
,当我将其更改为 document.getElementById("here").innerHTML = this.responseText;
时,程序可以正常工作。虽然这种 JavaScript 方法有效,但我想学习如何使用 JQuery 执行此操作,但我首先需要让它起作用。
我看过类似的问题,但要么不清楚,要么解决方案无效。我试过包括
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
在我的实际脚本之前,还有 src="jquery-3.4.1.js"
和 src="WebContent/WEB-INF/jquery-3.4.1.js".
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-3.4.1.js"></script>
<script type="text/javascript">
function change2(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
$("#here").html(this.responseText);
}
};
var current = document.getElementById("here").innerHTML.toString();
xmlhttp.open("GET", "helloWorld", true);
xmlhttp.send();
}
</script>
</head>
<body>
<h1 id="here">Hey World</h1>
<button type="button" onclick="change2()">Change</button>
</body>
</html>
我完全目瞪口呆。
尝试使用
$.ajax({url: "Your_URL", success: function(result){
$("#here").html(result);}});
jQuery
简单易行
你可以看看这篇文章
https://www.sitepoint.com/use-jquerys-ajax-function/
几天来我一直在努力 JQuery 开发一个简单的 hello world 程序。我的程序所做的是当我按下按钮时,它是否将 XMLHTTPRequest() 发送到 java servlet,并将 "Hey World" 更改为 "Hello World"。我是 JQuery 和 java 脚本的新手。我知道您的项目中需要有一个 jquery.js 文件,它目前位于我的 WebContent/WEB-INF/ 文件夹以及我的 JavaScript Resources 文件夹中。我正在使用 HTML 文件,唯一使用 JQuery 的行是 $("#here").html(this.responseText)
,当我将其更改为 document.getElementById("here").innerHTML = this.responseText;
时,程序可以正常工作。虽然这种 JavaScript 方法有效,但我想学习如何使用 JQuery 执行此操作,但我首先需要让它起作用。
我看过类似的问题,但要么不清楚,要么解决方案无效。我试过包括
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
在我的实际脚本之前,还有 src="jquery-3.4.1.js"
和 src="WebContent/WEB-INF/jquery-3.4.1.js".
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-3.4.1.js"></script>
<script type="text/javascript">
function change2(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
$("#here").html(this.responseText);
}
};
var current = document.getElementById("here").innerHTML.toString();
xmlhttp.open("GET", "helloWorld", true);
xmlhttp.send();
}
</script>
</head>
<body>
<h1 id="here">Hey World</h1>
<button type="button" onclick="change2()">Change</button>
</body>
</html>
我完全目瞪口呆。
尝试使用
$.ajax({url: "Your_URL", success: function(result){
$("#here").html(result);}});
jQuery
简单易行你可以看看这篇文章 https://www.sitepoint.com/use-jquerys-ajax-function/