ajax调用不能在我的ubuntu中运行xamp?

时间:2015-10-08 08:50:11

标签: php ajax codeigniter

控制器:

 <?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 queury
    // 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? 在我的时间.php索引方法iam只打印“echo time();”仅

任何人都可以帮助我吗?我想调用该控制器,它将在我的textarea中返回服务器的时间值

3 个答案:

答案 0 :(得分:1)

试试这个:

$.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);
});

答案 1 :(得分:1)

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/

答案 2 :(得分:0)

你的ajax调用是错误的改变它:

$.get("welcome/yourfunctionName", function (time) {
      // update the textarea with the time
      alert("hello");
      $("#text").html("Time on the server is:" + time);
    });