$.ajax({ type: "GET", url: '', dataType: "html",
The url is blank.. try putting the path to the webservice
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
I've added line numbers and formatted this for easier reading.
/* 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>
/* 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 */ }
/* 30 */ Route::get('/', array('as' => 'pages', 'uses' => 'PageController@index'));
/* 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>
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?.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)./
' on line [30],
so leaving this empty or as '/index
' will not work.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\"}"
.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>
public function getPropertyDetails() {
$filter = Input::get('href');
$view = DB::table('property_details')
->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
->get();
return Response::json($view);
}
Route::get('/property_details', 'PageController@getPropertyDetails');
<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>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community