我在另一个匿名函数中有一个 ajax 调用。我遇到的问题是它的长度为零。
//data_ajax_target equals '#partial_f_Picture'
Debug.Log($(data_ajax_target).length); // equal zero.
这可以防止从 ajax 调用返回的 html 替换 div 的内容。
这是我的 div
<div id="#partial_f_Picture">
<div id="fileuploader-small-f_Picture"
data-ajax-uploadurl="...omitted..."
data-ajax-target="#partial_f_Picture">
</div>
</div>
这是我简化的 javascript
$(function ()
{
FileUploaderSmallReady();
});
...
function FileUploaderSmallReady()
{
var uploaderDiv = $('[id^="fileuploader-small"]').each(function ()
{
var data_ajax_uploadurl = $(this).attr('data-ajax-uploadurl');
var data_ajax_target = $(this).attr('data-ajax-target');
var uploadersmall = new qq.FileUploader({
element: document.getElementById($(this).attr('id')),
action: data_ajax_uploadurl,
onComplete: function (file, response, responseJSON)
{
var data_ajax_url = responseJSON['data_ajax_url'];
if (typeof data_ajax_url != 'undefined')
{
$.ajax(
{
type: "GET",
url: data_ajax_url,
beforeSend: AjaxBegin(),
success: function (html)
{
Debug.Log(data_ajax_target);
//== #partial_f_Picture
Debug.Log($(data_ajax_target).length);
//== 0
$(data_ajax_target).html(html);
}
});
}
}
});});} //moved braces up to prevent code from being in a scroll window.