I have an ajax call within another anonymous function. The problem I am having is that the length of this is zero.
//data_ajax_target equals '#partial_f_Picture'
Debug.Log($(data_ajax_target).length); // equal zero.
This prevents the html returned from the ajax call from replacing the contents of the div.
Here is my div
<div id="#partial_f_Picture">
<div id="fileuploader-small-f_Picture"
data-ajax-uploadurl="...omitted..."
data-ajax-target="#partial_f_Picture">
</div>
</div>
This is my reduced 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.
Change
<div id="#partial_f_Picture">to<div id="partial_f_Picture">. The#in the selector means “it’s an id” (as opposed to.which means “it’s a class” and lack-of-prefix which means “it’s a dom tag” (p,div, etc)).