所以我很确定我的问题不在于ajax函数,因为它之前有效。我相信这个问题来自实际模型。所以我会发布这个......看起来很长,我可能做错了,所以让我们从那里开始......
好的,如果我从模型中删除以下代码,则ajax表单应该提交。没有问题。但是,如果我将此代码保留在那里,所有发生的事情都会出现加载图标,不会消失,页面也不会转移到下一步。我得到一个Failed to load resource: the server responded with a status of 500 (Internal Server Error)
指向我的模型。
有什么突出的吗?
// Add or update campaign on database
public function add_campaign()
{
// grab campaign session data
$id = $this -> session -> userdata('user_name');
$campaign = $this -> session -> userdata('campaign_name');
$website = $this -> session -> userdata('campaign_user_website');
$headline = $this -> session -> userdata('campaign_headline');
$bar_color = $this -> session -> userdata('campaign_bar_color');
$head_color = $this -> session -> userdata('campaign_head_color');
$main_color = $this -> session -> userdata('campaign_main_color');
$thanks_msg = $this -> session -> userdata('campaign_thanks');
//grab scorecard options
$email_q = $this -> input -> post('email');
$brand_q = $this -> input -> post('brand');
$design_q = $this -> input -> post('design');
$usability_q = $this -> input -> post('usability');
$support_q = $this -> input -> post('support');
$service_q = $this -> input -> post('service');
$recommend_q = $this -> input -> post('recommend');
$suggestion_q = $this -> input -> post('suggestion');
$comments_q = $this -> input -> post('comments');
$created = date('Y-m-d H:i:s');
// insert OR if campaign already exists, update the campaign values and date modified
$this -> db -> query("
INSERT INTO campaigns (id, campaign, website, headline, bar_color, head_color, main_color, thanks_msg, email_q, brand_q, design_q, usability_q, support_q, service_q, recommend_q, suggestion_q, comments_q, created)
VALUES ('$id', '$campaign', '$website', '$headline', '$bar_color', '$head_color', '$main_color', '$thanks_msg', '$email_q', '$brand_q', '$design_q', '$usability_q', '$support_q', '$service_q', '$recommend_q' '$suggestion_q', '$comments_q', '$created',)
ON DUPLICATE KEY UPDATE campaign='$campaign', modified='$created'
");
}
为需要的人提供更多信息
控制器功能:
public function embed_step()
{
//Create campaign on database
$this -> build_model -> add_campaign();
$data['embed_view'] = 'partials/embed'; // display view
if ($this -> input -> post('ajax')) // is 'ajax' variable from jQuery function exists, load:
{
$this -> load -> view($data['embed_view'], $data);
//$this->session->unset_userdata('user_url'); // kill session data
}
}
AJAX FUNCTION(部分):
var score_options = {
email: $('.email_score').val(),
brand: $('.brand_score').val(),
design: $('.design_score').val(),
usability: $('.usability_score').val(),
support: $('.support_score').val(),
service: $('.service_score').val(),
recommend: $('.recommend_score').val(),
suggestion: $('.suggestion_score').val(),
comments: $('.comments_score').val(),
ajax : '1' // needed for controller, to verify that request is ajax
};
//display ajax loader animation
$('#loading').show();
$.ajax({
url : 'ajax/embed_step',
type : 'POST',
data : score_options,
success : function(msg) {
$('.wizardContent').html(msg);
// output success in this container
$.scrollTo(0, 500);
// scroll to top on success
$('#loading').hide();
// hide loading icon
}
});
return false;
查看输入示例(所有内容相同,名称和类别,等等)
<!-- Scorecard options -->
<div class="scordOption roundtop">
<div class="checkicon"><input type="checkbox" name="email" class="email_score" value="1"></div>
<div class="scoreOptionTxt">What is your email address?</div>
</div>
答案 0 :(得分:1)
你可以在你的ajax电话中试试吗?
var _ajax_url = "<?php echo site_url('ajax/embed_step'); ?>";
url : _ajax_url
也尝试这个 .htaccess ,对我来说它适用于很多主机:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]