我正在努力解决jquery问题。目的是调用部分方法,它在第一次按钮单击时执行,但任何后续点击都会导致错误
预期()启动箭头功能,但得到';'而不是'=>'
我试过替换半冒号,交换函数()for()=>和其他各种组合,但我真的不知道我要交换的地方;对于a => (我认为这是错误告诉我的事情吗?)
$().ready(function () {
$(".page-number").on("click", function () {
var selectedPage = parseInt($(this).html());
$.ajax({
url: '@Url.Action("_PartialViewBeingCalled", "Pv")',
data: { 'page': selectedPage },
success: function (data) {
$("#pvId").html(data)
}
})
})
})
在阅读this question之后,我还尝试将以下代码块添加到结尾
.bind(this)
这个错误意味着什么,我该如何解决? (为什么它第一次有效但后续通话无效?)
编辑:
我在我的ajax请求中添加了fail: function(data) { console.log(data) }
,我的整个页面的全部内容,部分视图和页面调用部分视图返回两次,如下所示(请注意脚本也会返回两次 - 我认为它不会我拿着脚本进行测试的区别?):
<div id="properties">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Visible</th>
<th>Address</th>
<th>Contact</th>
<th>Telephone</th>
<th>Email ID.</th>
<th>Viewings</th>
<th>Book Viewing</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7">
<div id="dataTables-example_filter" class="dataTables_filter">
<input type="search" class="form-control input-sm" aria-controls="dataTables-example" placeholder="Search:">
</div>
</td>
</tr>
</tfoot>
<tbody>
<tr class='clickable-row' data-href='<a href="/Property/Index/5">Property</a>'>
<td>Yes</td>
<td>test</td>
<td>WV60NH</td>
<td>test</td>
<td>test</td>
<td>5</td>
<td><a href="<a href="/Property/Index/5">Property</a>" class="btn btn-default fa fa-book"> Book</a></td>
</tr>
<tr class='clickable-row' data-href='<a href="/Property/Index/5">Property</a>'>
<td>Yes</td>
<td>test</td>
<td>WV60NH</td>
<td>test</td>
<td>test</td>
<td>5</td>
<td><a href="<a href="/Property/Index/5">Property</a>" class="btn btn-default fa fa-book"> Book</a></td>
</tr>
</tbody>
</table>
</div>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_length" id="dataTables-example_length">
<label>
<select name="dataTables-example_length" aria-controls="dataTables-example" class="form-control input-sm">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select> records per page
</label>
</div>
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
<ul class="pagination pull-right">
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">1</a>
</li>
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">2</a>
</li>
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">3</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<script>
$(function () {
$(".page-number").on("click", function () {
var selectedPage = parseInt($(this).html());
$.ajax({
url: '/Property/_PropertyTable',
data: { 'page': selectedPage },
fail: function (data) {
console.log(data);
},
success: function (data) {
console.log(data);
$("#properties").html(data);
}
});
});
});
</script>
Index:436
<div id="properties">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Visible</th>
<th>Address</th>
<th>Contact</th>
<th>Telephone</th>
<th>Email ID.</th>
<th>Viewings</th>
<th>Book Viewing</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7">
<div id="dataTables-example_filter" class="dataTables_filter">
<input type="search" class="form-control input-sm" aria-controls="dataTables-example" placeholder="Search:">
</div>
</td>
</tr>
</tfoot>
<tbody>
<tr class='clickable-row' data-href='<a href="/Property/Index/5">Property</a>'>
<td>Yes</td>
<td>test</td>
<td>WV60NH</td>
<td>test</td>
<td>test</td>
<td>5</td>
<td><a href="<a href="/Property/Index/5">Property</a>" class="btn btn-default fa fa-book"> Book</a></td>
</tr>
<tr class='clickable-row' data-href='<a href="/Property/Index/5">Property</a>'>
<td>Yes</td>
<td>test</td>
<td>WV60NH</td>
<td>test</td>
<td>test</td>
<td>5</td>
<td><a href="<a href="/Property/Index/5">Property</a>" class="btn btn-default fa fa-book"> Book</a></td>
</tr>
</tbody>
</table>
</div>
<div class="row">
<div class="col-sm-6">
<div class="dataTables_length" id="dataTables-example_length">
<label>
<select name="dataTables-example_length" aria-controls="dataTables-example" class="form-control input-sm">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select> records per page
</label>
</div>
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
<ul class="pagination pull-right">
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">1</a>
</li>
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">2</a>
</li>
<li class="paginate_button" aria-controls="dataTables-example" tabindex="0">
<a href="javascript:void();" class="page-number">3</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<script>
$(function () {
$(".page-number").on("click", function () {
var selectedPage = parseInt($(this).html());
$.ajax({
url: '/Property/_PropertyTable',
data: { 'page': selectedPage },
fail: function (data) {
console.log(data);
},
success: function (data) {
console.log(data);
$("#properties").html(data);
}
});
});
});
</script>
答案 0 :(得分:3)
我发现了问题。它是javascript:void();
。你应该删除它。希望它有所帮助。
答案 1 :(得分:0)
请尝试以下
$(function () {
$(".page-number").on("click", function () {
var selectedPage = parseInt($(this).html());
$.ajax({
url: '@Url.Action("_PartialViewBeingCalled", "Pv")',
data: { 'page': selectedPage },
success: function (data) {
$("#pvId").html(data)
}
})
})
})
希望,因此它会起作用!
答案 2 :(得分:0)
我不认为我会收到答案,问题不在于我的jquery,但是我试图更新部分视图并使用html助手
@{Html.RenderAction("_PartialView", "Controller");}
将此更改为
@{Html.RenderPartial("_PartialView");}
解决了这个问题。我还将我的脚本移动到一个单独的文件中