Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel 4 + AJAX not working
    primarykey
    data
    text
    <p>I am very new to Laravel 4 and I'm trying to test AJAX request.</p> <p>In my <code>script.js</code> I have this:</p> <pre><code>(function() { $("#login-submit").click(function(e) { e.preventDefault(); return $.ajax({ type: "POST", url: "laravel/ajax/login", //i put my public in "localhost/laravel/public/" cache: false, data: 'email:' + $("#email").val(), success: function(data) { return alert(data); }, error: function(response) { return alert("ERROR:" + response.responseText); } }); }); }).call(this); </code></pre> <p>That is called from this html file:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;label for="email"&gt;Email: &lt;/label&gt; &lt;input type="text" id="email" /&gt; &lt;label for="email"&gt;Password: &lt;/label&gt; &lt;input type="password" id="password" /&gt; &lt;button id="login-submit"&gt;Log In&lt;/button&gt; &lt;/form&gt; &lt;script type="text/javascript" src="assets/js/jquery/jquery.custom.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="assets/js/script.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Controller class:</p> <pre><code>class AuthController extends BaseController { public function login() { echo 'success'; } } </code></pre> <p>And router:</p> <pre><code>Route::get('/', function() { return View::make('homepage'); }); Route::post('/ajax/login', 'AuthController@login'); </code></pre> <p>By clicking <code>Log In</code> it should be echoing "success" but instead it throws this error:</p> <pre><code>ERROR:{ "error": { "type": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException", "message": "", "file": "C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php", "line":1429 } } </code></pre> <p>What's wrong in this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload