【发布时间】:2012-07-16 12:17:31
【问题描述】:
我在执行代码时收到以下错误:Microsoft JScript 运行时错误:由于错误 80020101 无法完成操作。
以下链接是我在 Stackoverflow 上找到的内容: Ajax request problem: error 80020101
var div = $("<div class='modal'>").html($(result.getWebFormDesignFieldContentsResult));
传入的信息result.getWebFormDesignFieldContentsResult是一长串HTML和JAVASCRIPT,还没有解析成DOM。我只是觉得这很奇怪,因为前几天我让它工作,然后试图添加额外的功能......打破它。 :(
传入的字符串相当大,但类似于:
<div>input tags for filtering</div>
<select><option></option>...[150 option tags]... </select>
<anchor tag to return contents>
<script type = "text/javascript">
...stuff fires related to the above items...
</script>
我认为将作为字符串传递的信息放入 div 标签中存在问题,因为它可能不像脚本标签。
有没有其他人做到这一点,或者给我一些关于如何处理这个问题的指示?我可能想做一个字符串对象,然后相应地分解内容,只把html放在html中,然后以不同的样式处理js。
结果字符串 (result.getWebFormDesignFieldContentsResult)
您也可以访问这里: http://jsfiddle.net/3kFv2/
<table style='width:inherit;'>
<tr>
<td>
<input type='text' id ='queryInput' onkeypress = 'clearTimeout(timerVar); timerVar = setTimeout(function(){ fetchFieldInfo($("#queryInput").val()); },1000);' />
</td>
<td style = 'text-align:right;'>
<a class = 'modalButton' id = 'queryButton' runat='server' value = 'Re-Filter' onCLick = '$("div.modal").fadeOut(); fetchFieldInfo($("#queryInput").val());'>Re-Filter</a>
</td>
</tr>
<tr>
<td colspan='2' style='margin-left:auto; margin-right:auto; text-align:center;'><select size = '20' id = 'selectList' name = 'selectList' ><option value = '1000'>Abutment Notes</option><option value = '2300'>Abutments Notes</option><option value = '2302'>Abutments Notes Maint Need</option><option value = '2301'>Abutments Notes Remarks</option><option value = '10942'>Concrete Deterioration Maint Need</option></select></td>
<td>
<div style='width:300px;height:300px;' id = 'modalInfoPanel'>
</div>
</td>
</tr>
<tr>
<td></td>
<td style='text-align:right;'>
<a class = 'modalButton' id = 'buttonReturnValue' value = 'Return Selected Element' onClick='$("div.modal, div.overlay").fadeOut();'>Return Selected Element</a>
</td>
</tr>
</table>
<script type = 'text/javascript'>
function ajaxDisplayContents(value){
//alert(value.val());
/*
$('#selectList option').each(function(){
return $(this).val() == '';
}).attr('selected','selected');
*/
$.ajax({
type: 'POST',
url: WEBSERVICE_URL + '/fetchFieldInfo',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({'fe_id': value.val().toString()}),
success: function(result, textStatus, jqXHR){
$('#modalInfoPanel').html(result.fetchFieldInfoResult);
},
error: function(xhr, status, message){
$('#modalInfoPanel').html(status + ' ' + message);
}
});
}
$('select#selectList').change(function(){
ajaxDisplayContents($(this));
});
$(function(){
$('ul li').click(function(){ clicker(this); });
});
function clicker(x){
if($(x).next().is('li') || $(x).next().length == 0){
$.ajax({
type: 'POST',
url:,
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({}),
success: function(result){
$(x).after($('<ul>').append($(result['METHODResult']));
$(x).next().find('li').click(function() clicker(this); });
},
error: function(){
alert('failed to fetch');
}
});
}else if($(x).next().is('ul')){
$(x).next().slideUp(function(){ $(this).remove(); });
}
}
</script>
【问题讨论】:
-
如果你有一个 HTML 字符串,你可以直接将它传递给
.html()函数,你不必先将它包装在一个 jQuery 对象中。 -
是的,我知道。我把它放在那里,我原来的方式和你说的完全一样。我只是在检查它是否有问题。
-
我们能看到更多代码吗?查看您如何进行 AJAX 调用等会很有用。还包括来自 AJAX 响应的完整
<script>标记。 -
等待代码编辑。
-
我把所有的字符串都放到了 HTML 中,并没有把它分开,因为这就是 jquery 要做的,用 jquery 的 .html() 函数