Hi I have dynamically added functionality like adding a customer to a customer list appear in mouse over event . it has add new list item and once the user clicks it a textbox appears and once the user enters valid content it adds the newly entered item to the list saves it and displays the newly added thing with a tick. and when a user click on already ticked item it deletes from the list .
when i implement this functionality locally we can add a customer to many lists from one try . but when i upload the application and try it it saves a new customer group but when i trying to add more from a one shot it only added the last one. the previously added customers key is going with the request . if the customer s key already available it deletes the customer from the group which already being added . this works more like facebook’s friend list which you can find in friends page we can add friends to different lists.
is there a way to synchronize jquery ajax requests . can any one help?
$('.newcustomerlist').live("keypress",function (event) {
var element_id = $('.custitem').attr('id');
var customer_key = null;
var url_key = null;
if (element_id != null) {
customer_key = element_id.split('#')[0]
url_key = element_id.split('#')[1]
} else {
url_key = $(this).attr("id");
}
if(event.which == '13') {
var cust_list_name = $(this).val().trim();
var val = (/^[a-zA-Z ]*[-a-zA-Z0-9_ ]+$/).test(cust_list_name);
if(val){
$.ajax({
type : "GET",
url : "/addcustomerfromhere/",
data : "cust_list_name=" + cust_list_name,
success : function (msg) {
new_customer_key = msg.customer_key ;
$.ajax({
type : "GET",
url : "/addcustomertolist/",
data : "url_key=" + url_key + "&customer_key =" + new_customer_key ,
success : function (data) {
$("ul.custlist").prepend("<li id="+ new_customer_key + "#"+ url_key + " class='custitem addedtocust'><span>" + msg.cust_list_name + "</span></li>");
$(".title").show();
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
$.notify({message: 'Apologies. Our servers are busy at this moment. Please try again later.', type: 'error'});
}
});
},
error : function (XMLHttpRequest, textStatus, errorThrown) {
$.notify({message: 'Apologies. Our servers are busy at this moment. Please try again later.', type: 'error'});
}
});
$(".addnew").show()
$(".newtext").hide()
} else {
}
}
});
you could add this to the ajax options: