如何设计Ajax Jquery检索的数据? [英] How to design a data that was retrieved by Ajax Jquery?
问题描述
嘿伙计们,
我能够以json格式从ajax中提取此结果并将其打印在html上
[{ id: 207, 标题: 测试, GenreName: Action, EntryDate: 2014-05-06 19:13:14}]
现在我不能弄清楚如何在表格中显示这些数据,每个列包含Id,Title,GenreName和EntryData。我无法从谷歌找到示例代码。或者至少我不能理解我在那里看到的东西。
如果你注意到结果上有[],在其他例子中我看不到Json格式有这种风格,我不知道它来自哪里,因为我的控制器只回应模型中的数据。
AJAX
$(' form.ajaxForm')。on(' submit', function (){
$ .ajax({
类型:' POST',
url:' http://localhost/AnimeInventory/index.php/maincontroller/testForAjax',
data:{search:$(< span class =code-string> #searchInput)。val(),searchType:$( #searchTypeID)。val()},
dataType:' JSON',
成功: function (smg ){
}
});
});
返回 false ;
CodeIgniterController
公共函数testForAjax(){
echo json_encode($这 - > inventoryModel->搜索());
}
谢谢,
(' form.ajaxForm')。on(' submit', function (){
.ajax({
类型:' POST',
url:' http://localhost/AnimeInventory/index.php/maincontroller/testForAjax',
data:{search:
( #searchInput)。val(),searchType :
Hey guys,
I was able to pull this result from ajax in json format and print it on an html
[{"id":"207","Title":"Test","GenreName":"Action","EntryDate":"2014-05-06 19:13:14"}]
Now I cant figure out how to diplay this data in a table, with each columns for Id, Title, GenreName and EntryData. I cant find sample codes from google either. Or at least I cant comprehend what I saw there,.
Also if you'll notice the result have [] on it, on other examples I dont see Json format having that kind of style, I dont know where it came from since my controller only did echo the data from the model.
AJAX
$('form.ajaxForm').on('submit',function() {
$.ajax({
type: 'POST',
url: 'http://localhost/AnimeInventory/index.php/maincontroller/testForAjax',
data:{ search: $("#searchInput").val(), searchType: $("#searchTypeID").val() },
dataType: 'JSON',
success: function(smg) {
}
});
});
return false;
CodeIgniterController
public function testForAjax(){
echo json_encode($this->inventoryModel->search());
}
Thanks,
('form.ajaxForm').on('submit',function() {
.ajax({ type: 'POST', url: 'http://localhost/AnimeInventory/index.php/maincontroller/testForAjax', data:{ search:
("#searchInput").val(), searchType:
这篇关于如何设计Ajax Jquery检索的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!