Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Either way you're going to use a jQuery POST to get the json/html from the server ajax style. Use the <code>error:</code> property in the jQuery <code>$.ajax(</code> function to handle a failed response.</p> <p><strong>Edit:</strong><br> This is a fairly simple function that adds/updates comments on thumbnail images from a html table:</p> <pre><code> function commentImage(pgiID) { var commentText = $("table.gallery td a#"+pgiID).attr("title"); var newComment = prompt("Create or update the photo comment:",commentText); if(newComment!=null) { // post comment back to server $("div#"+pgiID+" a").hide(); $("div.photoAdminBlock img.loading"+pgiID).show(); $.ajax({ type: "POST", url: "/Activities/UpdateImageComment", data: {id: pgiID, commentText: newComment}, success: function() { // set title attr $.getJSON("/Activities/GetPgiComment/"+pgiID,null,function(data, textStatus) { $("table.gallery td a#"+pgiID).attr("title",data); $("div.photoAdminBlock img.loading"+pgiID).hide(); $("div#"+pgiID+" a").show(); $("table.gallery td a#"+pgiID).trigger("click"); }); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("There was an error when trying to update the comment.\nPlease refresh this page and try again or contact support."); $("div.photoAdminBlock img.loading"+pgiID).hide(); $("div#"+pgiID+" a").show(); } }); } } </code></pre> <p>I think the ideal thing would be to have your jQuery ajax handle 500-series HTTP responses appropriately. This is prob more 'MVC-ish'. ;)</p>
 

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