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!
What I do is to judge whether a class is in class or not, and get the array data from the backend interface! A total of four classes,
The code is as follows:
Copy Code code as follows:
function Ajaxcheckedlessonsaction () {
3583 languages, Class 8.
1500 languages, Class 9.
2717 Physics, Class 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) {
$lessonsChecked [' 9yuwen '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']);
} elseif ($lessons [' id '] = = 2717) {
$lessonsChecked [' 8wuli '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']);
} elseif ($lessons [' id '] = = 1612) {
$lessonsChecked [' 9wuli '] = $this->verifycheckedlessons ($lessons [' Startime '], $lessons [' Endtime ']);
}
}
$json = Json_encode ($lessonsChecked);
Echo $json;
}
Interface processes data, JSON the data,
The foreground parses the JSON data
Copy Code code as follows:
The process of entering the page
$.ajax ({
Type: "POST",
URL: "/default/index/ajaxcheckedlessons",
Data: "",
Success:function (response) {
if (response) {
var data = eval (' (' +response+ ') ');
if (data[' 8yuwen ']) {
$ ("#8yuwen"). attr ("style", "color:red;");
}else{
$ ("#8yuwen"). attr ("Style", "");
}
if (data[' 8wuli ']) {
$ ("#8wuli"). attr ("style", "color:red;");
}else{
$ ("#8wuli"). attr ("Style", "");
}
if (data[' 9yuwen ']) {
$ ("#9yuwen"). attr ("style", "color:red;");
}else{
$ ("#9yuwen"). attr ("Style", "");
}
if (data[' 9wuli ']) {
$ ("#9wuli"). attr ("style", "color:red;");
}else{
$ ("#9wuli"). attr ("Style", "");
}
}else{
Alert ("Error");
}
}
});
The red part is the core of the JSON code.
This completes the processing of the array! Asynchronous Array Data Delivery!