Reputation: 107
I am using a url variable in my links to pass a unique ID, which is run through ajax and injected using .html()
. See code below
I have added a timeout, added empty()
to the div before populating,
LINK TO PAGE:
<a href="member.html?id=' + member.id + '" data-role="none" data-transition="slide">
PAGE CREATION:
$(document).on( "pageshow", "#member-page", function(event) {
.....
var request = $.ajax({
url: serviceURL + 'member_profile',
method: "GET",
data: { id : id },
dataType: "html"
});
request.done(function( data ) {
...
alert(html);
$('#member-profile').hide().empty().html(html).fadeIn();
});
request.fail(function( jqXHR, textStatus, errorThrown ) {
alert( "Request failed Line 752: " + textStatus + " - " + jqXHR.responseText);
$.mobile.loading( "hide" );
});
});
Sometimes it works and sometimes it doesn't. Eventhough the alert(html)
always shows data.
Is there a better way to pass the id, and to render the page, like using pagebeforecreate
Upvotes: 0
Views: 78
Reputation: 57309
You missed to show us the most important part of your code. It would be so much easier to analyze your code if you have also included $.ajax section.
I would presume two possible solutions, also I think both of these solutions are entwined in your case.
Have you tried to do it like this:
$.ajax({
url: "YOUR ENDPOINT"
}).done(function(html) {
$('#member-profile').hide().empty().html(html).fadeIn();
});
This way content will be cleaned/filled only when it is actually received.
Upvotes: 1