Note that there are some explanatory texts on larger screens.

plurals
  1. POClear and reload div with data via AJAX and jQuery
    primarykey
    data
    text
    <p>I have an ajax call that requests data from a Coldfusion CFC method and displays the data in a div. There is also a link to delete this data which uses the same CFC but a different method to delete. Both methods work independently just fine. What I can't seem to figure out is how to encapsulate the call in a function and refresh the div once the deletion has been successful. Here is the code:</p> <p><strong>ajax call</strong></p> <pre><code> var caseid = &lt;cfoutput&gt;'#URL.ID#'&lt;/cfoutput&gt;; var siteurl = &lt;cfoutput&gt;'#APPLICATION.url#'&lt;/cfoutput&gt;; var html = ""; function assetsPost() { $.ajax({ cache: false, type:'GET', url:'cfc/cfc_Asset.cfc?method=qAsset&amp;returnformat=json', dataType: "json", data: { assetgrp_id: caseid, }, success:function(data) { if(data) { // DO SOMETHING jQuery.each(data, function(i, val) { $('#picoutputannotation').html(data[i].annotation); var asset_id = data[i].value; var img = siteurl + 'assets/images/thumbs_check2/' + data[i].thumb; var removeimg = siteurl + 'assets/images/remove.png'; var annotation = data[i].annotation; html += "&lt;div class='block-pics'&gt;"; html += "&lt;img src='" + img + "'&gt;"; html += "&lt;div class='note'&gt;"; html += annotation; html += "&lt;/div&gt;"; html += "&lt;div class='block-pics-remove'&gt;"; html += "&lt;a class='delete-asset' id='" + asset_id + "'&gt;&lt;img src='" + removeimg + "'&gt;&lt;/a&gt;"; html += "&lt;/div&gt;"; html += "&lt;div class='bot'&gt;&lt;/div&gt;"; html += "&lt;/div&gt;"; }); $('#picoutput').html( html ); } else { // DO SOMETHING } } }); } assetsPost(); </code></pre> <p><strong>here is the deletion script:</strong></p> <pre><code> $(document).on("click", ".delete-asset", function() { var del_id = $(this).attr('id'); $.ajax({ type:'GET', url:'cfc/cfc_Asset.cfc?method=DeleteAsset&amp;returnformat=json', dataType: "json", data: { delete_id: del_id, }, success:function(data) { if(data) { // DO SOMETHING $('#picoutput').empty(); {assetsPost()}; $('#picoutput').fadeIn('fast'); } else { // DO SOMETHING } } }); }); </code></pre> <p><strong>here is the html:</strong></p> <pre><code>&lt;div class="grid_6"&gt; &lt;div id="picoutput"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload