Parsing jQuery AJAX response

前端 未结 6 853
囚心锁ツ
囚心锁ツ 2020-12-06 09:29

I use the following function to post a form to via jQuery AJAX:

$(\'form#add_systemgoal .error\').remove();         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-06 10:19

    Imagine that this is your Json response

    {"Visit":{"VisitId":8,"Description":"visit8"}}
    

    This is how you parse the response and access the values

        Ext.Ajax.request({
        headers: {
            'Content-Type': 'application/json'
        },
        url: 'api/fullvisit/getfullvisit/' + visitId,
        method: 'GET',
        dataType: 'json',
        success: function (response, request) {
            obj = JSON.parse(response.responseText);
            alert(obj.Visit.VisitId);
        }
    });
    

    This will alert the VisitId field

提交回复
热议问题