Uncaught TypeError: Illegal invocation:error with modal form
Uncaught TypeError: Illegal invocation:error with modal form
这是我在 Whosebug 中的第一个问题,在我的 html 页面中我有一个 table,我想使用模态形式将数据发送到 servlet。但是,我有这个错误:Uncaught TypeError: Illegal invocation。
table.html
<body>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>ACTION</th>
</tr>
<tr>
<td>1</td>
<td>JHON</td>
<td><input type="button" value="display" class="d"></td>
</tr>
<tr>
<td>2</td>
<td>Max</td>
<td><input type="button" value="display" class="d"></td>
</tr>
</table>
<div id="dialog-form">
<input type="text" value="" id="id">
<input type="text" value="" id="name">
</div>
<div id="res"></div>
</body>
test.js
$(".d").click(function(){
var id =$("#id").attr("value",$(this).parent().prev().prev().text());
var name =$("#name").attr("value",$(this).parent().prev().text());
$("#dialog-form").dialog({
modal: true,
buttons: {
"Send":function () {
$.post("Controller",{id:id,name:name},function(data){
$("#res").html(data);
}) ;
}
Servlet.java
String name=request.getParameter("name");
String id=request.getParameter("id");
out.println(id +" "+ name);
我猜你正在尝试修改值并在后端更新它。
var id =$("#id").attr("value",$(this).parent().prev().prev().text());
var name =$("#name").attr("value",$(this).parent().prev().text());
这会将对象分配给变量 id 和 name。您不能在 ajax 中发送它们,也不需要。因此错误。
在您的情况下,您需要使用 id 和 name 值更新模态文本框并将它们发送到服务器。另请注意,由于它是一个文本框,因此您需要发送用户可能已更改的更新值。
因此我们进行以下更改。
首先我们只是在模态的文本框中设置 id 和 name 值
$("#id").attr("value", $(this).parent().prev().prev().text());
$("#name").attr("value", $(this).parent().prev().text());
然后在ajaxpost中,我们发送从文本框中获取的更新值
$.post("Controller", {
id: $("#id").val(),
name: $("#name").val()
}, function (data) {
$("#res").html(data);
});
这是我在 Whosebug 中的第一个问题,在我的 html 页面中我有一个 table,我想使用模态形式将数据发送到 servlet。但是,我有这个错误:Uncaught TypeError: Illegal invocation。
table.html
<body>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>ACTION</th>
</tr>
<tr>
<td>1</td>
<td>JHON</td>
<td><input type="button" value="display" class="d"></td>
</tr>
<tr>
<td>2</td>
<td>Max</td>
<td><input type="button" value="display" class="d"></td>
</tr>
</table>
<div id="dialog-form">
<input type="text" value="" id="id">
<input type="text" value="" id="name">
</div>
<div id="res"></div>
</body>
test.js
$(".d").click(function(){
var id =$("#id").attr("value",$(this).parent().prev().prev().text());
var name =$("#name").attr("value",$(this).parent().prev().text());
$("#dialog-form").dialog({
modal: true,
buttons: {
"Send":function () {
$.post("Controller",{id:id,name:name},function(data){
$("#res").html(data);
}) ;
}
Servlet.java
String name=request.getParameter("name");
String id=request.getParameter("id");
out.println(id +" "+ name);
我猜你正在尝试修改值并在后端更新它。
var id =$("#id").attr("value",$(this).parent().prev().prev().text());
var name =$("#name").attr("value",$(this).parent().prev().text());
这会将对象分配给变量 id 和 name。您不能在 ajax 中发送它们,也不需要。因此错误。
在您的情况下,您需要使用 id 和 name 值更新模态文本框并将它们发送到服务器。另请注意,由于它是一个文本框,因此您需要发送用户可能已更改的更新值。
因此我们进行以下更改。
首先我们只是在模态的文本框中设置 id 和 name 值
$("#id").attr("value", $(this).parent().prev().prev().text());
$("#name").attr("value", $(this).parent().prev().text());
然后在ajaxpost中,我们发送从文本框中获取的更新值
$.post("Controller", {
id: $("#id").val(),
name: $("#name").val()
}, function (data) {
$("#res").html(data);
});