Parsing jQuery AJAX response

前端 未结 6 851
囚心锁ツ
囚心锁ツ 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 09:56

    Since you are using $.ajax, and not $.getJSON, your return type is plain text. you need to now convert data into a JSON object.

    you can either do this by changing your $.ajax to $.getJSON (which is a shorthand for $.ajax, only preconfigured to fetch json).

    Or you can parse the data string into JSON after you receive it, like so:

        success: function (data) {
             var obj = $.parseJSON(data);
             console.log(obj);
        },
    

提交回复
热议问题