How to use Ajax with jQuery in Laravel 4?

前端 未结 1 1753
小蘑菇
小蘑菇 2021-02-11 09:03

I am brand new to Laravel 4 and seeing if I can convert my website over to it (previously written without a framework). I can\'t get AJAX (via jQuery) to interact properly with

相关标签:
1条回答
  • 2021-02-11 09:42

    Your base path to your laravel project is localhost/laravel/public/ but your AJAX-request goes to just localhost. There're some methods for fixing this.

    Method 1:

    This is the most preffered method. (in my opinion)

    Instead of using nginx, apache for starting a web server, you can use PHP's built in web server.

    Open a terminal window (or cmd in Windows), cd into the main directory for your project (the one with vendor, app and public directories) and type the command php artisan serve. This will create a PHP-server on localhost:8000 and your base path will be /.

    There's a lot of options, for example php artisan help serve" if you want to see them all.

    After you've done so your code should work.

    Method 2

    If you want to use nginx or apache you should add a virtualhost for your project.

    That can be done though the configs.

    Apache: http://httpd.apache.org/docs/current/vhosts/examples.html

    Nginx: http://wiki.nginx.org/ServerBlockExample

    After that you should add a new entry to the hosts file.

    Method 3

    As you said you could add a BASE variable before the '/types/'+$brand.

    Your request goes to localhost/types/$brand.

    It should go to localhost/laravel/public/types/$brand.

    Just replace '/types/'$brand with '/laravel/public/types'+$brand

    0 讨论(0)
提交回复
热议问题