This article is mainly to JS to the Ajax return array processing for a detailed introduction, the need for friends can come to the reference, I hope to help you.
Introduction: Ajax asynchronous transmission, can transmit strings, but the array of such data, it is not very good to pass, this time how to do? The answer is that you can use JSON to process the data in the background JSON encoding! Then the client, through JS to parse. So the problem is solved! JSON is a good data format! I do is asynchronous to determine whether a class is in the class state, will get the array data from the background interface! A total of four classes, code as follows: code is as follows: function ajaxcheckedlessonsaction () { //3583 language 8 class //1500 language 9 //2717 physical 8 //1612 Physics Class 9 $whereLessons = array (); $whereLessons [' Lessons.id in (?) '] = Array (3583, 1500, 2717, 1612); $daoLessons = new Dao_lessons (); $alllessons = $daoLessons->getlessons ($whereLessons); //print_r ($alllessons); exit; $lessonsChecked = array (); foreach ($alllessons as $lessons) { if ($lessons [' ID '] = = 3583) { $lessonsChecked [' 8yuwen '] = $this->verifycheckedlessons ($lessons [' Startime '], $ lessons[' Endtime ']); ElseIf ($lessons [' id '] = = 1500) { &N Bsp $lessonsChecked [' 9yuwen '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']); ElseIf ($lessons [' id '] = = 2717) { &N Bsp $lessonsChecked [' 8wuli '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']); ElseIf ($lessons [' id '] = = 1612) { &N Bsp $lessonsChecked [' 9wuli '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']); { $json = Json_encode ( $lessonsChecked); Echo $json; } Interface processing data, JSON data, foreground to the JSON data parsing code as follows://Enter the page on the processing of $ . Ajax ({ type: "POST", URL: "/default/in Dex/ajaxcheckedlessons ", data:", SUCC Ess:function (response) { if (response) { var data = eval (' (' +response+ ') '); if (data[' 8yuwen ']) { &NBS P $ ("#8yuwen"). attr ("style", "color:red;"); }else{ &NB Sp $ ("#8yuwen"). attr ("Style", "");   & nbsp if (data[' 8wuli ']) { $ ("#8wuli"). attr ("Style", " color:red; "); }else{ &NB Sp $ ("#8wuli"). attr ("Style", ""); & nbsp if (data[' 9yuwen ']) { $ ("# 9yuwen "). attr (" style "," color:red; "); }else{ &NB Sp $ ("#9yuwen"). attr ("Style", ""); &NBSP if (data[' 9wuli ']) { &NB Sp $ ("#9wuli"). attr ("style", "color:red;"); }else{ &NB Sp $ ("#9wuli"). attr ("Style", ""); & nbsp }else{ alert ("error"); & nbsp } { }); The red part is the core code for JSON. This completes the processing of the array! Asynchronous Array Data Delivery!