控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('form-view');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
我的观点:
$( document ).ready(function () {
// set an on click on the button
$("#button").click(function () {
// get the time if clicked via an ajax get query
// see the code in the controller time.php
alert("hi");
$.get("/index.php/getTime", function (time) {
// update the textarea with the time
alert("hello);
$("#text").html("Time on the server is:" + time);
});
});
});
它没有调用我的控制器time.php?
在我的time.php索引方法中;回声时间(("只有
有人能帮我吗?我想调用那个控制器,它会在我的文本区域中返回服务器的时间值
试试这个:
$.get("<?php echo base_url();?>index.php/welcome/getTime", function (time) {
// update the textarea with the time
alert("hello");
$("#text").html("Time on the server is:" + time);
});
try to make the function and run ajax onclick event like this
<script>
function deleteDomain()
{
$.ajax({
url:"<?php echo site_url('Test/deleteDomain');?>/",
success:function(data)
{
alert(data);
}
});
}
</script>
<a href="javascript:void(0)" onclick="deleteDomain()" title="Delete" class="icon-2 info-tooltip">Delete</a>
有关如何在codeigniter中调用ajax请求的更多信息,请尝试http://w3code.in/2015/10/how-to-edit-delete-and-update-data-without-refreshing-page-in-codeigniter/
您的ajax调用错误,请将其更改为:
$.get("welcome/yourfunctionName", function (time) {
// update the textarea with the time
alert("hello");
$("#text").html("Time on the server is:" + time);
});