Reputation: 1257
As the title states, I am trying to perform a simple task of when my ajax post successfully completes my database query, I would like to add the word "Success" into an empty DIV using the AJAX success option. I can't figure out how to get that text to appear. Any help is appreciated. Thanks.
Here is my working AJAX post:
<script>
$(function(){
$("#noteForm").submit(function(){
// prevent native form submission here
$.ajax({
type: "POST",
data: $('#noteForm').serialize(),
dataType: 'json',
url: "actionpages/link_notes_action.cfm?id=2",
success: function() {
$(".response").append($( "Success" ) );
}
});
return false;
});
});
</script>
I have a div in my page with id of "response" that is nested inside the div of my form.
<!--- Modal HTML embedded directly into document --->
<div id="LinkNotes#id#" style="display:none;">
<p>These are the notes for: #link_description#</p>
<form id="noteForm">
<textarea id="noteText" name="noteText" cols="45" rows="10">#notes#</textarea><br />
<input name="submit" id="submitForm" type="submit" value="Update"><div class="response" id="response"></div>
<input type="hidden" name="hidden" value="#get_dashboard_links.ID#">
</form>
</div>
Upvotes: 1
Views: 3517
Reputation: 1257
I was able to find the answer from this post
Apparently removing
dataType: 'json',
from my script fixed it.
Upvotes: 0
Reputation: 72857
So close!
Since you just want to append a string, you only have to pass that string to .append
.
Replace:
.append($( "Success" ) );
With:
.append("Success");
$("Success")
looks for a <Succes />
tag, which it doesn't find, resulting in an empty set that's being appended.
As you can probably imagine, appending "nothing" doesn't do particularly much ;-)
Upvotes: 5