Support the ongoing development of Laravel.io →
Database Views Blade
Last updated 2 years ago.
0

$.ajax({ type: "GET", url: '', dataType: "html",

The url is blank.. try putting the path to the webservice

0

Thanx for the reply...

I am using index() function, so in url i have passed my function name but still it's not generating view but in my console i can see the output onclick my function is excuting. like this i have tried $.ajax({type:"GET", url:"/index" dataType:"html"

please help me

0

Your Post

I've added line numbers and formatted this for easier reading.

Your AJAX Script

/*  1 */  <script>
/*  2 */      $(function () {
/*  3 */          $('.click').click(function () {
/*  4 */              alert($(this).attr('href'));
/*  5 */          });
/*  6 */      });
/*  7 */      $('.click').click(function (evt) {
/*  8 */          evt.preventDefault();
/*  9 */          var link = $(this).attr('href');
/* 10 */          $.ajax({
/* 11 */              type: "GET",
/* 12 */              url: '',
/* 13 */              dataType: "html",
/* 14 */              data: {
/* 15 */                  href: link
/* 16 */              }
/* 17 */          });
/* 18 */      }).done(function (url) {
/* 19 */          // pass the url back to the client after you incremented it
/* 20 */          window.location = url;
/* 21 */      });
/* 22 */  </script>

This is my function

/* 23 */  public function index() {
/* 24 */      $filter = Input::get('href');
/* 25 */      $view = DB::table('property_details')
/* 26 */          ->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
/* 27 */          ->get();
/* 28 */      return Response::json($view);
/* 29 */  }

My Routes

/* 30 */  Route::get('/', array('as' => 'pages', 'uses' => 'PageController@index'));

My Views

/* 31 */  <ul class="properties-filter">
/* 32 */      <li class="selected"><a href="All" data-filter="*" class="click"><span>All</span></a></li>
/* 33 */      <li><a href="featured" data-filter=".property-featured" class="click"><span>Featured</span></a></li>
/* 34 */      <li><a href="rent" data-filter=".property-rent" class="click"><span>Rent</span></a></li>
/* 35 */      <li><a href="sale" data-filter=".property-sale" class="click"><span>Sale</span></a></li>
/* 36 */  </ul>

My Response:

  • As you can see after formatting, lines [7] and [18] match up with each other. This will result in an error, since jQuery's click method does not have a done method to call back on. I'm assuming that you meant to attach the .done() method to the $.ajax() call?
  • Assuming you meant to place the .done() method on the $.ajax() call, keep in mind that the function will pass back all of the data, not just a specific url (unless that's what your controller is returning).
  • Line [12] is empty, but this needs to have a url in it. Your route is defined as '/' on line [30], so leaving this empty or as '/index' will not work.
  • In line [13], you define the dataType as html, but on line [28], you are returning json. This will be interpreted as html, meaning you will get back a string that looks like: "{\"id\":1,\"sale_or_rent\":\"That's All Folks\"}".
  • I'm not sure how you have everything else set up, but the index() function is generally used to display the home page, not to make ajax calls to.

Here's something that should be more along the lines of what you need (note: not tested):

<script>
    $(function () {
        $('.click').click(function () {
            alert($(this).attr('href'));
        });
    });
    $('.click').click(function (evt) {
        evt.preventDefault();
        var link = $(this).attr('href');
        $.ajax({
            type: "GET",
            url: '/property_details',
            dataType: "json",
            data: {
                href: link
            }
        }).done(function (data) {
            // I'm assuming that the 'property_details' table has a 'url' field?
            // If not, just replace this with whatever you need.
            if (data && data.hasOwnProperty('url')) {
                window.location = data.url;
            }
        });
    });
</script>

Function

public function getPropertyDetails() {
    $filter = Input::get('href');
    $view = DB::table('property_details')
        ->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
        ->get();
    return Response::json($view);
}

Routes

Route::get('/property_details', 'PageController@getPropertyDetails');

View

<ul class="properties-filter">
    <li class="selected"><a href="All" data-filter="*" class="click"><span>All</span></a></li>
    <li><a href="featured" data-filter=".property-featured" class="click"><span>Featured</span></a></li>
    <li><a href="rent" data-filter=".property-rent" class="click"><span>Rent</span></a></li>
    <li><a href="sale" data-filter=".property-sale" class="click"><span>Sale</span></a></li>
</ul>
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

techiva techiva Joined 9 Jan 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.