Php TypeError:值未实现接口HTMLInputElement
我正在尝试使用jQueryAjax发布表单,在单击发布表单时遇到了这个错误。Php TypeError:值未实现接口HTMLInputElement,php,ajax,jquery,Php,Ajax,Jquery,我正在尝试使用jQueryAjax发布表单,在单击发布表单时遇到了这个错误。 TypeError:值未实现接口HTMLInputElement 以下是我的JavaScript代码: $('document').ready(function () { $('#update').click(function () { jQuery.post("update_category", { c_id: c_id, c_name: c_
TypeError:值未实现接口HTMLInputElement
以下是我的JavaScript代码:
$('document').ready(function () {
$('#update').click(function () {
jQuery.post("update_category", {
c_id: c_id,
c_name: c_name,
c_description: c_description
},
function (data, textStatus) {
if (data == 1) {
$('#response').html("Thank You!!..We Will Get Back To You Soon..!!");
$('#response').css('color', 'green');
} else {
$('#response').html("Some Error Occurred");
$('#response').css('color', 'red');
}
});
});
});
我的表格:
<div id="form">
<form>
<!-- PRONT DROP DOWN HERE !-->
<input type="text" name="c_id" id="c_id" disabled="disble" placeholder="'.strtoupper($r['c_id']).'" value="'.strtoupper($r['c_id']).'" ></input>
<input type="text" name="c_name" id="c_name" disabled="disble" placeholder="'.strtoupper($r['c_name']).'" value="'.strtoupper($r['c_name']).'"></input>
<textarea rows="4" class="field span10" name="c_description" id="c_description" disabled="disble" placeholder="Description">'.strtoupper($r['c_description']).'</textarea>
</form>
</div>
“.strtoupper($r['c_description'])”
在HTML代码中包含服务器端PHP代码的表单
PHP代码应按以下方式编写
<input type="text" name="c_id" id="c_id" disabled="disble" placeholder="<?php echo strtoupper($r['c_id']) ; ?> " value="<?php echo strtoupper($r['c_id']) ; ?> " ></input>
试试这个
jQuery.post
用这个
$.post
这里是完整的代码
$(document).ready(function () {
$('#update').click(function () {
$.post("update_category", {
c_id: c_id,
c_name: c_name,
c_description: c_description
},
function (data, textStatus) {
if (data == 1) {
$('#response').html("Thank You!!..We Will Get Back To You Soon..!!");
$('#response').css('color', 'green');
} else {
$('#response').html("Some Error Occurred");
$('#response').css('color', 'red');
}
});
});
});
希望它能帮助检查下面的代码。代码中缺少id=“response”的span或div,并将jquery.post替换为$.post。为文件名update_category指定扩展名
<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$('document').ready(function(){
var c_id = '1', c_name = 'test', c_description = 'testing';
$('#update').click(function(){
$.post("update_category.php", {
c_id:c_id,
c_name: c_name,
c_description: c_description
}, function(data){
if(data == 1){
$('#response').html("Thank You!!..We Will Get Back To You Soon..!!");
$('#response').css('color','green');
}
else
{
$('#response').html("Some Error Occurred");
$('#response').css('color','red');
}
});
});
});
</script>
</head>
<body>
<div id="form">
<form>
<!-- PRONT DROP DOWN HERE !-->
<input type="text" name="c_id" id="c_id" placeholder="" value="" />
<input type="text" name="c_name" id="c_name" placeholder="" value="" />
<textarea rows="4" class="field span10" name="c_description" id="c_description" placeholder="Description"></textarea>
<input type="button" id="update" value="Update" />
<span id="response"></span> <!-- This is missing in your form -->
</form>
</div>
</body>
</html>
$('document').ready(函数(){
变量c_id='1',c_name='test',c_description='testing';
$(“#更新”)。单击(函数(){
$.post(“update_category.php”{
c_id:c_id,
c_name:c_name,
c_说明:c_说明
},函数(数据){
如果(数据==1){
$('#response').html(“谢谢!!…我们很快会回复您的!!”;
$('#response').css('color','green');
}
其他的
{
$('#response').html(“发生了一些错误”);
$('#response').css('color','red');
}
});
});
});
如果在ajax请求中发送jQuery对象,则会生成此错误。
因此,在您的情况下,c_id
、c_name
或c_description
中的一个很可能是一个jQuery对象,表示输入字段,而不是输入元素的.val()
值。尝试在变量中使用值
$('document').ready(function () {
$('#update').click(function () {
jQuery.post("update_category", {
c_id: c_id.val(),
c_name: c_name.val(),
c_description: c_description.val()
},
function (data, textStatus) {
if (data == 1) {
$('#response').html("Thank You!!..We Will Get Back To You Soon..!!");
$('#response').css('color', 'green');
} else {
$('#response').html("Some Error Occurred");
$('#response').css('color', 'red');
}
});
});
.strtoupper($r['c_description'])。
它应该是服务器端代码吗?!为什么你用$('document')而不是$(document)?yaa.strtoupper($r['c_description'])我也把它当作服务器端,它是这样的……我把它放在我的表单字段中,现在把它发布到更新查询中。你如何获得c_id,c_name,来自formfriend的c_描述我正在使用codeigniter,我已经给了你控制器方法代码,所以不需要编写i@user2488557是否在使用前定义了c_id etc变量?我正在使用codeigniter,所以不需要.php扩展,只需给出控制器的方法名称。。。我试过使用$.post仍然无法将vlue post发送给控制器如何从表单中获取c_id、c_名称、c_描述的值这是一个古老的答案,但我要感谢您。它应该是mark作为一个好的答案。只是在解决我自己的问题时对你的答案投了更高的票…我引用的是元素而不是值…+1@milo lamar