I want to run a post where I am returned with some data from the server. I received the area from the Chrome console report. Now, 234 is what I want to be returned and I assume that the ajax_file.php does work because it is returning the 234, but I am getting the error. What is wrong with my code?
<script type="text/javascript">
$('#button_id').click(function() {
var search_term = $('#search_term').val();
$.post('ajax_file.php', {search_term: search_term}, function (data) {
$(data).appendTo('#div_tag');
});
});
</script>
<div id="div_tag"></div>
Since you pass
datatojQuery, it is interpreted as selector and the value234is an invalid selector.Instead of passing the response to
jQuery, reverse the operands and use.append[docs]:Although it is possible to pass an HTML string to
jQuery, your string does not contain any HTML (tags) and therefore jQuery does not know that you want it to be interpreted as such.