.ajax在本地服务器上发布并获得响应,在Web主机上没有响应

时间:2010-08-13 22:37:23

标签: ajax codeigniter

我正在使用ajax调用进行次要计算,然后返回值并将其显示在提交表单的页面相同页面中。在Firebug中,它说它调用了函数,但没有得到响应。 (我有一个类似的形式,写入一个工作正常的数据库,似乎因为它不需要响应 - firebug说它也没有得到对该脚本的响应。)奇怪的是我写了这个在我的本地服务器在网站上实现之前,一切都按计划运行。我在本地服务器和Web服务器上都使用Code Igniter,但我不知道这是否与它有关。无论如何,任何帮助都会很棒。我现在略微崭露头角,所以现在这有点超出了我的境界。

由于

编辑:.js

$(document).ready(function() {

    $('#submit').click(function(){

    var formdata = {
        years: $('#years').val(),
        rate: $('#rate').val(),
        principle: $('#principle').val(),
        periods: $('#periods').val(),
        continuous: $('#continuous').val()
        }

    $.ajax({
        url: "http://localhost:8888/CodeIgniter_1.7.2/index.php/timevalueshow/submit",
        type: 'POST',
        data: formdata,
        success: function(data){
                $('#replace').replaceWith('<p>'+data+'</p>');                       
        }
    });

    return false;
});


 });

php提交功能

function submit(){

    $years = $this->input->post('years');
    $rate = $this->input->post('rate');
    $principle = $this->input->post('principle');
    $periods = $this->input->post('periods');
    $isCont = $this->input->post('continuous');

    $params = array(
        'years' => $years, 
        'rate' => $rate, 
        'principle' => $principle, 
        'periods' => $periods, 
        'isCont' => $isCont
    );

    $this->load->library('timevalue', $params);

    return $this->timevalue->FVFactor();
}

2 个答案:

答案 0 :(得分:0)

这适用于开发人员,而不是服务器,因为您正在调用 localhost

// this will have the client call itself on this particular page (wont work)
url: "http://localhost:8888/CodeIgniter_1.7.2/index.php/timevalueshow/submit",

以上代码应该只是:

// this is relative to the document ROOT, will work on server but not on dev!
// you can set it relative to the calling page using ../ as needed
url: "/index.php/timevalueshow/submit",

答案 1 :(得分:0)

请问是跨域进行的吗?请记住,mydomain.com被视为与www.mydomain.com不同的域名。

我最近遇到了类似的情况。我从mydomain.com请求了一个页面,该页面向www.mydomain.com上的脚本发出了一个AJAX请求。该请求未被提出,因为它被视为跨域。它与您描述的症状相同。在Firebug和Chrome Developer Console中,我看到一个空响应,没有错误消息。

问题是CodeIgniter根据$config['base_url']设置生成绝对URL。如果您使用与$config['base_url']中配置的域名不同的域名访问该站点,则可能会遇到此类问题。

相关问题