2010-08-13 65 views
1

我正在使用ajax调用做一个小的计算,然后返回值并将其显示在提交表单的页面中。在Firebug中它表示它调用该函数,但没有得到响应。 (我有一个写入数据库的类似表单,工作正常,似乎是因为它不需要响应 - 萤火虫表示它也未能在该脚本上得到响应。)奇怪的是,我在我的本地服务器,然后在网站上实施,一切按计划进行。我在本地服务器和Web服务器上都使用了Code Igniter,但我不知道这是否与它有关。无论如何,任何帮助将是伟大的。我稍微有点新,所以在这个时候这已经超出了我的境界。.ajax帖子和获取本地服务器的响应,没有响应的网页主机

感谢

编辑:.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(); 
} 
+0

我们可以看到一些代码,你也试图从本地到远程或反之亦然? – Robert 2010-08-13 22:43:31

+0

@Robert有代码。我试图将数据发送到托管我的站点的服务器,然后返回数据。 – tshauck 2010-08-13 23:38:45

回答

0

难道该请求正在取得跨域?请记住,mydomain.com被视为与www.mydomain.com不同的域名。

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

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

+0

如何解决这些问题? – 2011-12-02 18:38:44

0

这部作品的开发,而不是在服务器上,因为你在呼唤本地主机

// 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", 
+0

嗨,我不小心复制了本地文件而不是服务器上的文件。对函数的调用通过,没有任何回应。 – tshauck 2010-08-13 23:57:41

+0

@tshauck我总是试图杀死节拍是让服务器**总是**回显一些东西,所以你可以肯定的是,如果函数正在运行**它正在输出一些东西**。如果你可以的话,我也会有一个'error_log('函数运行');'在PHP上,以确保。请做到这一点,并让我们知道,即使返回的东西,你仍然没有得到答案。 THKS! – Frankie 2010-08-14 00:07:40

+0

嗨,所以我试了一下,没有收到任何错误信息,但是我不确定是否正确设置了它,所以我在函数内部运行了一个邮件(),以便在发送邮件时向我发送邮件。 – tshauck 2010-08-14 00:30:50