我的页面是domain.com/home/details/1
在我的 jQuery AJAX 调用中,我有以下内容,但是当它进行该调用时,它会调用domain.com/home/details/home/getdata
我该怎么做才能让它得到正确解决?
$(document).ready(function () {
oTable = $('#example').dataTable({
"bServerSide": true,
"sAjaxSource": "Home/GetData/",
"bProcessing": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"bFilter": true,
"bAutoWidth": false,
"fnServerData": function (sSource, aoData, fnCallback) {
/* Add some extra data to the sender */
//aoData.push({ "filtervalue": $('#filtervalue').val(), "Options": $('#Options').val() });
$.getJSON(sSource, aoData.concat($('form').serializeArray()), function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
});
}
});
});
绝对地always在 ASP.NET MVC 中处理 url 时使用 URL 助手。绝对地never像你一样硬编码网址。
So:
"sAjaxSource": "@Url.Action("GetData", "Home")"
如果这是在单独的 javascript 文件中,您可以使用 HTML5data-*
上的属性#example
:
<div id="example" data-url="@Url.Action("GetData", "Home")">
...
</div>
然后在你单独的js中你可以使用.data() http://api.jquery.com/data/ method:
"sAjaxSource": $('#example').data('url')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)