jquery ajax 响应剥离 html标签
我有一个 javascript / jquery 函数,它应该用同一行的“编辑模式”版本替换表中的一行。它在行上按钮的 onclick 事件上触发,代码的简化版本为:
function EditRow(itemID) {
editable_row = getUrl('row.php?action=' + 'edit' + '&itemID=' + itemID );
$('[row_itemID=' + itemID + ']').html(editable_row);
}
(...row_itemID 是该行的 TR 标记的属性...如 [tr row_itemID="27"] )
function getUrl(addr) {
var r = $.ajax({ type: 'GET', url: addr, async: false, dataType: "text" }).responseText; return r;
}
(我也尝试将“dataType:”设置为“html”或完全忽略它)
row.php 应该返回该行内容的“编辑模式”版本,但由于某种原因,TD 标签似乎被剥离过程,也许是$.ajax() 函数认为包含 TD 而不包含 TR 的响应无效。
row.php?action=edit&itemID=27
的视图源显示 TD ,alert(editable_row);
也是如此,但是 alert( $('[row_itemID=27]').html());
没有。
row.php 代码的简化版本:
<?php
if ($_GET['action'] == 'edit') {
$item = ItemDataAccess::Read($_GET['itemID']);
?>
<td><input type="text" name="itemID" value="<?php echo $item->itemID ?>" /></td>
<td><input type="text" name="name" value="<?php echo $item->name ?>" /></td>
<td><input type="text" name="description" value="<?php echo $item->description ?>" /></td>
<?php
}
?>
现在有人如何让它将纯粹的 html 响应插入到 TR 标记中吗?
I have a javascript / jquery function which is supposed to replace a row in a table with an "Edit Mode" version of the same row. it fires on the onclick event of a button on the row and a simplified verion of the code would be:
function EditRow(itemID) {
editable_row = getUrl('row.php?action=' + 'edit' + '&itemID=' + itemID );
$('[row_itemID=' + itemID + ']').html(editable_row);
}
(...row_itemID is an attribute of the TR tag for the row... as in [tr row_itemID="27"])
function getUrl(addr) {
var r = $.ajax({ type: 'GET', url: addr, async: false, dataType: "text" }).responseText; return r;
}
(i have alse tried setting "dataType:" to 'html' or leaving it out altogether)
row.php should return the "Edit Mode" version of the contents of the row but for some reason the TD tags appear to get stripped in the process, maybe the $.ajax() function consideres a response containing TD 's without TR 's invalid.
A view-source of row.php?action=edit&itemID=27
displays the TD 's and so does alert(editable_row);
, but alert($('[row_itemID=27]').html());
doesn't.
A simplified version of row.php code:
<?php
if ($_GET['action'] == 'edit') {
$item = ItemDataAccess::Read($_GET['itemID']);
?>
<td><input type="text" name="itemID" value="<?php echo $item->itemID ?>" /></td>
<td><input type="text" name="name" value="<?php echo $item->name ?>" /></td>
<td><input type="text" name="description" value="<?php echo $item->description ?>" /></td>
<?php
}
?>
Does anyone now how to get it to insert an unadulterated html response into the TR tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的围绕
$.ajax()
编写了一个包装器吗?您是否错过了$.get()
和.load()
?而且,不寒而栗你使用的是async: false
而不是回调,为什么?就是这样。
You really wrote a wrapper around
$.ajax()
? Did you miss$.get()
and.load()
? And, shudder you're usingasync: false
instead of a callback, why?That's it.