Ajax.BeginForm, Calls Action, Returns JSON, How do I access JSON object in my OnSuccess JS Function?

前端 未结 4 1654
孤街浪徒
孤街浪徒 2020-12-24 03:23

Ajax.BeginForm calls an action and then returns JSON. How do I access JSON object in my OnComplete js function?

so my Ajax.BeginForm<

4条回答
  •  甜味超标
    2020-12-24 03:44

    this is an example of doing the post yourself but the concept is the same. Notice the parameter to the onsuccess function. the parameter gives you access to whaever the controller returned. If it is Json data then that is what you get. If the controler returned a partial view then you get the html for the view. You can call the JQuery $.ParseJSON() function on the returned data.

    $.post('/Assessment/GetAssessmentResults/' + SelectedId,   
    function onsuccess(e) {  
       var json_object = $.parseJSON(e);  
    }, "POST");  
    

提交回复
热议问题