how to use jquery ajax success data
I'm constantly running into an issue where i am unable to use the ajax success data to perform another function. as per below
$("#addproperty_state").keyup(function(){
var vardata = $(this).val();
var urlPro ="<?php echo HTTP_PHP; ?>ajax_common.php?action=get_area&area="+vardata;
$.ajax({
type: "POST",
开发者_JS百科 url: urlPro,
dataType: "text",
async:false,
success: function(data) {
$('#statelist').html(data);
}
});
return false;
});
I want to now use the result of the ajax call so that i can populate another text box with the result value.
$("#statelist li").click(function(){
var statename = $(this).attr("title");
$("#addproperty_state").val(statename);
});
but if i was now to click on the li nothing happens. How can i use the ajax result to actually do something else with it? Any assistance would be greatly appreciated. Thank you
Use the .live function:
$("#statelist li").live("click", function(){
var statename = $(this).attr("title");
$("#addproperty_state").val(statename);
});
It works for elements that get added to the dom later on
精彩评论