append div after executing $post
Greeting, I would like to append some div after correct success is returned from my $.post My code looks as follows:
$.post("/MyApp/Market/CheckIfIndustryIsValid", { id: $(NODE).attr("id") },
function(obj) {
if (obj.Success) {
if ($.inArray($(NODE).attr("id"), array) === -1) {
array.push($(NODE).attr("id"));
$("#Industries").val(array);
arrayOfNames.push($(NODE).attr("title"));
$("#SelectedIndustries").html($(NODE).attr("ti开发者_StackOverflow社区tle"));
}
else {
array.splice(array.indexOf($(NODE).attr("id")), 1);
$("#Industries").val(array);
arrayOfNames.splice(array.indexOf($(NODE).attr("title")), 1);
$("#SelectedIndustries").val(arrayOfNames);
$("#resultMessage").append($(NODE).attr("title"));
}
}
else {
alert("Please choose different industry"); //failure, show message
}
However these lines:
$("#SelectedIndustries").val(arrayOfNames);
$("#resultMessage").append($(NODE).attr("title"));
are not working. For test purposes I also added some alert("test") just before these two lines and it has been executed. Can someone please help.
Have you been able to get any results by using alert( $(NODE).attr("title") )
? (Or using the Firebug Console, if you are using Firefox.)
Have you checked the value of arrayOfNames
? I can see the .slice()
and .push()
actions, but what is the original, and subsequent, values of that variable?
Also, setting the .val()
attribute of a div
is not possible. If you are trying to set the contents of the div
, then you will need to use $( '#selectedIndustries' ).innerText( 'The Contents of the DIV' )
, or ...).innerHTML( 'The <b>Contents</b> of the <i>DIV</i>' )
(if the contents contains HTML tags).
精彩评论