我有带有 ajax 的 JS 函数,下面是 url:
var company_count = COMPANIES_PER_PAGE;
....
url: '<%=j companies_path(start: ' + company_count + ', f: params[:f]) %>',
....
company_count += COMPANIES_PER_PAGE;
但这给了我脚本:
url: '/companies?f=k&start=company_count',
我想得到前任:
url: '/companies?f=k&start=30',
整个脚本
<script>
var COMPANIES_PER_PAGE = <%= @companies_per_page %>;
var company_count = COMPANIES_PER_PAGE;
$(document).ready( function(){
checkScroll();
});
function checkScroll() {
if (nearBottomOfPage()) {
$('#loading_more_'+(company_count-COMPANIES_PER_PAGE)).fadeTo(200, 1);
$.ajax({
type: "GET",
url: '<%=j companies_path(start: company_count, f: params[:f]) %>',
dataType: "script"
});
company_count += COMPANIES_PER_PAGE;
} else {
setTimeout(checkScroll, 250);
}
}
</script>