jquery - eOnSuccess will be executed even if the Ajax.actionlink did not succsfully execute & also the OnSuccess will not display alerts if using firefox -


i have following ajax.actionlink responsible deleting answer objects:-

    <td>              @ajax.actionlink("delete", "delete", "answer",             new { id = answer.answersid },               new ajaxoptions               {                    confirm = "are sure want delete answer ?",                   httpmethod = "post",                   updatetargetid = @answer.answersid.tostring(),                   onsuccess = "deleteconfirmation", onfailure = "deletionerror"               })           </td> 

and following deleteconfirmation.js :-

function deleteconfirmation() {     jalert('the answer deleted succsfully', 'deletion confirmation');         $(this).remove(); } 

were ajax.actionlink call folloiwng action method:-

[httppost]         public actionresult delete(int id)         {             var = repository.findanswer(id);              repository.deleteanswer(a);             repository.save();             return content(""); assessments.");         } 

but facing following problem:-

  1. if delete object using firefox web browser jalert('the answer deleted succsfully', 'deletion confirmation'); not shown , while shown using ie, might reason?

  2. i browse intended web page whice show answer object, manually delete answer object database, after click on delete ajax link behind deleted object (before refreshing page), expecting onfailure script executed did not , rather null exception raised.

  3. is there way provide jquery confirm box instead of confirm = "are sure want delete answer ?", br

*edit:- * lot detailed answer have following points need clarifiy:-

in delete controller action returning empty content (return content("")) , yet have defined updatetargetid = @answer.answersid.tostring() in link makes firefox throw error because cannot insert empty content dom

i returning empty string action method becuase not need display user after deletion ,since removing deleted object dom using $(this).remove(); should partial view _foo contains in case?

if on other hand handle exception on server , consume without leaving propagate , return 200 http status code

but in case action method not handling null pointer exception, on other hand ajax.actionlink onfailure not executed if null pointer exception raised!!.

thanks again ur help..

1) if delete object using firefox web browser jalert('the answer deleted succsfully', 'deletion confirmation'); not shown , while shown using ie, might reason?

in delete controller action returning empty content (return content("")) , yet have defined updatetargetid = @answer.answersid.tostring() in link makes firefox throw error because cannot insert empty content dom - doesn't make sense. guess ie little more tolerant kind of errors. guess in ie, while don't error, given dom element doesn't refresh @ after delete.

so have return actual content such partial view delete controller action:

[httppost] public actionresult delete(int id) {     var = repository.findanswer(id);     repository.deleteanswer(a);     repository.save();     return partialview("_foo"); } 

now contents of partial view used refresh given dom element.

2) browse intended web page whice show answer object, manually delete answer object database, after click on delete ajax link behind deleted object (before refreshing page), expecting onfailure script executed did not , rather null exception raised.

if exception, thrown on server side , 500 http status code returned onfailure callback invoked. if on other hand handle exception on server , consume without leaving propagate , return 200 http status code, onsuccess callback execute if there error on server.

3) there way provide jquery confirm box instead of confirm = "are sure want delete answer ?"

sure, use onbegin instead of confirm:

@ajax.actionlink(     "delete",      "delete",      "answer",     new { id =  answer.answersid },     new ajaxoptions     {         httpmethod = "post",         updatetargetid = answer.answersid.tostring(),         onbegin = "deletebegin",         onsuccess = "deleteconfirmation",         onfailure = "deletionerror"     } ) 

and in deletebegin callback:

function deletebegin() {     // show whatever confirmation want here , return true     // proceed ajax request , false cancel it.      // example using standard confirm js method     // use whatever      var shouldproceed = confirm('are sure want delete answer ?');      return shouldproceed; } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -