bigData
bigData

Reputation: 1318

how to use ajax in laravel 4

I am trying to use ajax in laravel 4. I followed the steps from this example: http://codehappy.daylerees.com/ajax-content

My code is listed below.

JavaScript :

        $.post(BASE+'checkUserName', {
            un: userName,
            }, function(data) {
                alert(data);
                //$('#content').html(data);
            });

Route :

 Route::post('checkUserName',function(){
    return true;
});

In a footer, I have this :

<script type="text/javascript"> var BASE = "<?php echo URL::base(); ?>"; </script>

The problem seems to be with variable BASE. When I view source, it shows :

<script type="text/javascript"> var BASE = "<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Whoops! There was an error.</title>

    <style>.cf:before, .cf:after {content: " ";display: table;} .cf:after {clear: both;} .cf 

    {*zoom: 1;}
body {
  font: 14px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
  color: #2B2B2B;
  background-color: #e7e7e7;
  padding:0}


.
.
.

Can someone give me a simple example of using ajax in laravel 4?

Upvotes: 2

Views: 2518

Answers (1)

Trying Tobemyself
Trying Tobemyself

Reputation: 3668

URL::base() was in L3 and in L4 it has been replaced with URL::to('/') or Request::root() Changelog (Laravel 4)

And just for info no need to declare Base variable like that you can directly use blade syntax in script,if it is embedded in your view

Upvotes: 2

Related Questions