I am developing an application that relies heavily on jQuery for user interaction.
(and if your browser does not support jQuery, update or do not use my application :)
As usual, one has functions for GET, SET and DELETE data from the table.
In my application, I gather and arrange a lot of information without reloading the page. For this, I mainly use jQuery.post.
Typical code in my JS file is as follows:
jQuery.post("mypath/jquery_getset_data.php", { instance: 'getItems_A', itemID: itemID_value},
function(data) {
populateItemList(data);
});
jquery_getset_data.php contains many if statements :
if($_POST['instance'] == 'getItems_A'){
// PHP code to get and process data from MySQL DB
}
if($_POST['instance'] == 'setItems_A'){
// PHP code to process and insert data to MySQL DB
}
Here is my question:
1:
, .
function createStoreList(data)
{
var ul = jQuery("<ul/>");
for (var i = 0; i < data.length; i++)
{
ul.append(
jQuery("<li/>")
.attr("id", "listItem_"+data[i].id)
.append(jQuery("<span/>")
.addClass("btnRemoveItem")
.attr("title", "Remove store from list")
.attr("id", data[i].id)
.click(function() { removeItemA(this); })
)
.append(data[i].name + ', ' + data[i].street)
);
}
return ul;
}
2
, switch. , .
.click(function() {
switch(instance)
{
case 'removeListItemA': removeListItemA(this); break;
case 'removeListItemA': removeListItemB(this); break;
case 'removeListItemA': removeListItemC(this); break;
}
})