I’m updating a list with some buttons via AJAX. My function works fine in general, however it produces a white screen after a while. This happens when I click the button and use the back button and repeat it a few times. When I refresh about 10 buttons that are provided on runtime with AJAX, it crashes after some clicks. When I refresh let’s say 20 buttons, it crashes immediately the first time I hit the back button. The LogCat doesn’t say anything by the time the app crashes. I tried to substituted the button() call with a livequery call which works but produces the same crash after some time.
I’m developing a native app. If I try it as a web-app in Firefox, it works perfectly without crashing.
I’m not sure if my problem has anything to do with the available memory. I’m testing with a Samsung Galaxy Ace which has approx. 50 MB internal memory left and a 1 GB SD card.
$(".warenkorb_class").click(function(e) {
e.stopImmediatePropagation();
e.preventDefault();
$.post("http://mydomain/backend.php",{
action: "warenkorb", kunden_id: $local_kunden_id },
function(data) {
$.mobile.changePage("#warenkorb");
$("#warenliste").html(data);
$("#warenliste").listview("refresh");
$(".warenliste_button_class").button();
}, "html");
});
I’m new to android development and I’ve been struggling with this problem for some days now and would be very happy if someone could help me on this.
Thanks and regards,
Florian
EDIT:
Here is the part of backend.php where the code for the buttons is created:
echo"<tr>";
echo utf8_encode("<td><a class='delete_button' href='#warenkorb' data-role='button' data-icon='delete' data-iconpos='notext' data-mini='true' data-inline='true' data-theme='b' id='1_$bestellungen_id'>Position löschen</a></td>");
echo utf8_encode("<td><a class='minus_button' href='#warenkorb' data-role='button' data-icon='minus' data-iconpos='notext' data-mini='true' data-inline='true' data-theme='b' id='2_$bestellungen_id'>eins weniger</a></td>");
echo"<td><a class='warenliste_button' href='#warenkorb' id='3_$bestellungen_id' data-mini='true'>$bestellungen_anzahl</a></td>";
echo utf8_encode("<td><a class='plus_button' href='#warenkorb' data-role='button' data-icon='plus' data-iconpos='notext' data-mini='true' data-inline='true' data-theme='b' id='4_$bestellungen_id'>eins mehr</a></td>");
echo utf8_encode("<td><a class='warenliste_button' href='#warenkorb' id='5_$bestellungen_id' data-mini='true' data-inline='true'>$produkte_bezeichnung</a></td>");
echo "</tr>";
I would have a look at optimising your code, try to remove the class selectors and replace them with id selectors, it that is not posible be more specific in your selector ie do button.warenliste_button_class.
I would sort that as the crashing could be due to script running out of memory while it is executing. Also checkout firebug/console to check ans see what is happening, Check for long running scripts, large amounts of data being posted etc.
Check out this link for more optimisation tips
http://www.archer-group.com/2011/technology/jquery-javascript-optimization
without more information like the functions and data that the jquery is being operated on i have no more suggestions.