我使用HTML
创建了一个链接 <a style="text-decoration: none; " href="{{URL::route('category.show', $category->id) }}">{{$category->name}}</a>
而不是使用普通链接,我想使用jQuery来实现这个
<input type="button" value="<?php echo $category->name; ?>" onClick="getPage(<?php echo $category->id; ?>);" /><?php ?>
<script type="text/javascript">
function getPage(id) {
$('#output').html('<img src="LoaderIcon.gif" />');
jQuery.ajax({
url: "{{ URL::route('category.show', $category->id) }}",
// i don't know how to declare the route URL in jQuery.
data:'id='+id,
type: "POST",
success:function(data){
$('#output').html(data);
}
});
}
getPage(1);
</script>
答案 0 :(得分:0)
定义您的网址路径,如下所示: -
<script type="text/javascript">var BASEURL = "'.$this->baseUrl.'"; </script>
<script type="text/javascript">
function getPage(id) {
$('#output').html('<img src="LoaderIcon.gif" />');
var path=BASEURL+'/category/'+id; // define path here
jQuery.ajax({
url: path,
data : {id: id},
type: "POST",
success:function(data){$('#output').html(data);}
});
}
getPage(1);
</script>
希望它会对你有所帮助: - )