我使用了一个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();
}发布于 2010-08-15 00:58:29
会不会请求是跨域发出的?请记住,与www.mydomain.com相比,mydomain.com被视为不同的域。
我最近遇到了类似的情况。我从mydomain.com请求了一个页面,它向www.mydomain.com上的一个脚本发出了AJAX请求。未发出请求,因为它被认为是跨域的。它的症状和你描述的一样。在Firebug和Chrome开发者控制台中,我看到一个空的响应,没有错误消息。
问题是CodeIgniter根据$config['base_url']设置生成绝对URL。如果您使用与$config['base_url']中配置的域名不同的域名访问站点,则可能会遇到此类问题。
发布于 2010-08-14 07:46:29
这在开发环境上工作,而不是在服务器上,因为您正在调用本地主机!
// 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",https://stackoverflow.com/questions/3481135
复制相似问题