0

所以我很确定我的问题不在于 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 功能(部分):

    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>
4

1 回答 1

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]
于 2012-11-23T18:06:05.933 回答