Please go to youtube and watch the jQuery series by jream. Plus the jquery site has complete examples.
Try.
$("#employeelist").val(result);
I watched all of them. Your the one who referred them to me before. the way its explained in his videos can't be done in laravel. If you ran my code that I have up top, it will not select the element with the specified id. The way I have it in my code is how he explained to do it
Lets try something, make a html form and put this in body:
<a id="trythis" href=""> [trythis ] </a>
At bottom of form put this above the </html> tag:
<script>
$(function() {
$("#trythis").click(function(event)
{
alert('jquery is working');
});
}); ///end
</script>
Name the form whatever you wish and of course load from a controller, and it will need a route.
And include jquery at top of this html form.
If you have jquery loaded right you should get the alert box.
If not you are not getting jquery loaded.
I have jquery in public/include
Top of from looks like this:
<html>
<head>
<script type="text/javascript" src="include/jquery.js"></script>
<link rel="stylesheet" href="include/style2.css" type="text/css">
</head>
Without knowing exactly what you are after, it's hard to give examples. But I got your code working after some additions:
route:
Route::get('wother', array('uses' => 'PownersController@wother'));
view:
<html>
<head>
<script type="text/javascript" src="include/jquery.js"></script>
<script type="text/javascript" src="include/myjq.js"></script>
<link rel="stylesheet" href="include/style2.css" type="text/css">
</head>
<body>
<a id="jsonjq" href=""> [clickme ] </a>
<a id="trythis" href=""> [trythis ] </a>
<div id="employeelist">
</div>
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
?>
</body>
<script>
$(function() {
$("#trythis").click(function(event)
{
alert('jquery is working');
event.preventDefault();
var oid = '1';
$.ajax({
url:'<?php echo "wother";?>',
type: 'GET',
data: 'id='+oid,
dataType: 'json',
success: function(result){
alert(result);
$("#employeelist").html(result)
}});
});
}); ///end
</script>
</html>
top of controller
use Illuminate\Contracts\Routing\ResponseFactory;
controller method
public function wother(ResponseFactory $response) {
$dummy = $_GET['id'];
$mydata = "howdy";
//echo $mydata;
return $response->json($mydata);
}
route that brings up the form
Route::get('jtest', array('uses' => 'PownersController@myjson'));
controller method for above
public function myjson() {
return \View::make('owner/jsontest');
}
So the jquery does work in laravel, again I do not know exactly what you are after, but you left out some
items on the ajax call. This example fully worked on my machine.
And since a get request, you have to send some bogus get to have it pass through.
P.S. This is exactly like the jream videos, but you have to know about the ResponseFactory.
I actually learned of this from the laracast forum.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community