duanliaoyu8419 2017-09-28 15:20
浏览 172

Ajax LARAVEL 419 POST错误

I would really appreciate some help on this. I tried tons of solutions as posted in this forum, but I cannot get it to work.

My ajax call is something like

$(document).ready(function() {
    $("#company").click(function() {
        $.ajax({
            type: "POST",
            dataType:'html',
            url : "/company",
            success : function (data) {
                $("#result").html(data);
            }
        });
    });
});

I am calling the view through my route

Route::post('/company', 'Ajaxcontroller@loadContent');

And controller

public function loadContent()
    {
        return view('listing.company')->render();
    }

My company.blade.php is

    @foreach ($companies as $company)
            <div class="posting-description">
            <h5 class="header"><a href="#"></a>{{$company->name}}
            </h5>
            <h5 class="header"> {{$company->streetaddress}} {{$company->postalcode}}</h5>  
            <p class="header">
             <span class="red-text"> <?= $service; ?> </span> is available on <span class="green-text"><?php echo $date; ?></span>
           </p>
    @endforeach

I am getting this error

POST http://127.0.0.1:8234/company 419 (unknown status)
  • 写回答

8条回答 默认 最新

  • dongtiao2976 2017-09-28 15:22
    关注

    You don't have any data that you're submitting! Try adding this line to your ajax:

    data: $('form').serialize(),
    

    Make sure you change the name to match!

    Also your data should be submitted inside of a form submit function.

    Your code should look something like this:

    <script>
        $(function () {
            $('form').on('submit', function (e) {
                e.preventDefault();
                $.ajax({
                    type: 'post',
                    url: 'company.php',
                    data: $('form').serialize(),
                    success: function () {
                        alert('form was submitted');
                    }
                });
            });
        });
    </script>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法