0

So I am trying to submit just an email address using ajax to get people to register and I have no idea why I am getting a 500 internal server error. I am new to ajax calls.

I have tried to follow the following tutorial: http://www.youtube.com/watch?v=TZv5cgua5f0 However I have done as they have said and still if I do a post with values I do not get to the desired controller method. If I do add data to the post then I get an internal server error.

javascript:

$('#email_submit').click(function() 
    {

        var form_data = 
        {
           users_email: $('#users_email_address').val()
        };
        $.ajax
        ({
            url: 'http://localhost/myZone/NewsLetter/submit',
            type: 'POST',
            data: form_data,
            success: function(msg)
            {
                alert(msg);
            }

        });

        return false;
    });

HTML

<div id="email_newsletter_signup" class="ajax_email_block_signup" >
        <h3>Sign up to the newsletter:</h3>
        <?php echo form_error('signup_email','<div id="email_error" class="error">','</div>');?>
        <h3>email: <input id="users_email_address" type="email" name="signup_email" value="<?php echo set_value('signup_email'); ?>" placeholder="Your email"/> </h3>

        <input id="email_submit" type="submit" name="submit"/>
    </div>

contoller

    public function index()
        {
                Assets::add_module_js('newsletter','email.js');
                //If included will be added
                Template::set_block('email_block','email_block');
                Template::render();
        }

    public function submit($email)
            {
                $success = $this->newsletter_model->set_unverified_email($email);
//                if($success === FALSE)
//                {
//                    Template::set_block('newsletter_error','newsletter_error');
//                }
//                else
//                {
//                    Template::set_block('newsletter_success','newsletter_success');
//                }
//                Template::render();
                return;
            }

I have a breakpoint inside the submit and it just wont be hit when I do a post

Thanks

4

2 回答 2

1

找到了我的解决方案。与篝火无关,但与codeigniter无关。它是 CSRF 令牌。

这是一篇关于对问题进行排序的优秀帖子:

http://aymsystems.com/ajax-csrf-protection-codeigniter-20

于 2013-09-03T17:21:06.367 回答
0

在发布之前将 csrf 令牌添加到数据中

$.ajax({
            type: "POST",
            url: url,
            data: {'<?php echo $this->security->get_csrf_token_name(); ?>':'<?php echo $this->security->get_csrf_hash(); ?>'}

        })

csrf 令牌需要随每个请求一起发送,因此需要由上述 echo 语句指定

于 2014-09-09T08:29:57.637 回答