Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Codeigniter提交Ajax表单-站点挂起+;500错误_Codeigniter_Codeigniter 2 - Fatal编程技术网

使用Codeigniter提交Ajax表单-站点挂起+;500错误

使用Codeigniter提交Ajax表单-站点挂起+;500错误,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,因此,我非常确定我的问题不在于ajax函数,因为它在以前工作过。我相信问题来自实际的模型。所以我会发布这个…看起来很长,我可能做错了什么,所以让我们从这里开始 好的,如果我从模型中删除以下代码,ajax表单将按其应该的方式提交。没有问题。但是如果我把这段代码留在那里,所发生的一切就是加载图标会出现,不会消失,页面也不会转移到下一步。我收到加载资源失败的:服务器响应状态为500(内部服务器错误),指向我的型号 有什么突出的吗 // Add or update campaign on databas

因此,我非常确定我的问题不在于ajax函数,因为它在以前工作过。我相信问题来自实际的模型。所以我会发布这个…看起来很长,我可能做错了什么,所以让我们从这里开始

好的,如果我从模型中删除以下代码,ajax表单将按其应该的方式提交。没有问题。但是如果我把这段代码留在那里,所发生的一切就是加载图标会出现,不会消失,页面也不会转移到下一步。我收到加载资源失败的
:服务器响应状态为500(内部服务器错误)
,指向我的型号

有什么突出的吗

// 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功能(部分):

查看输入示例(所有示例都相同,减去名称和类等)


你的电子邮件地址是什么?

您能在ajax调用中尝试一下吗

var _ajax_url = "<?php echo site_url('ajax/embed_step'); ?>";

 url : _ajax_url

使用Firebug查看来自CodeIgniter的实际错误消息。它将准确地告诉您出了什么问题。仅供参考,您应该清理您的查询。这一个容易受到SQL注入的攻击,帮个忙,替换所有的$This->input->post('something');使用$this->input->post('something',true);然后,您的请求似乎失败了,因此您需要检查给定的url是否正确,您是否也在使用htaccess删除index.php?@johncode对Firebug不太熟悉,但错误不会像Chrome那样出现在控制台中…@MikeBarwick您可以在html或config.js文件中的某个地方定义var\u ajax\u url(这始终是一个很好的做法)因此,在我的视图中创建
var
?在脚本链接到外部js之前?@MikeBarwick-yep如果可以,那么您应该创建一个config.js文件,包含在html中,在其中定义所有js-config-var,如下所示;)
<!-- 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>
var _ajax_url = "<?php echo site_url('ajax/embed_step'); ?>";

 url : _ajax_url
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]