Ajax in Codeigniter using jQuery

I have controller called `Time` this controller outputs the current time and that is loaded by using following code in a view. window.setInterval(function() { $.get('time/index', // when the Web server responds to the request function(time) { $('#mydiv').html(time+'
'); } ) }, 5000); As it can be seen only html response can be used only but what if I want `Time` controller to return array, object or even a variable etc how can I do that?
you should return the array using json_encode, ex: return json_encode($timeArray);, and then the ajax part you should decode and iterate the array, as you want

以上就是Ajax in Codeigniter using jQuery的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准