gpt4 book ai didi

Symfony 1.4 中的 Ajax 分页

转载 作者:行者123 更新时间:2023-12-04 06:09:33 24 4
gpt4 key购买 nike

我正在使用 symfony 1.4 并尝试使用 Ajax 调用对我的搜索结果进行分页,但遇到了困难。

我的 ajax 调用是对一个 Action (executeGetList) 进行的,我在其中传递了页面参数。这就是我进行ajax调用的方式:

var url = "<?php echo url_for("genre/getList"); ?>";
function loadPage(page)
{
$.ajax({
url: url+"?page="+page,
type: 'POST',
dataType: 'html',
timeout: 4000,
beforeSend: function(){
$('#loading').show();
},
complete: function(){
$('#loading').hide();
},
error: function(xhr, textStatus, errorThrown){
msg = "Error " + errorThrown;
alert(msg);
},
success: function(data){
$("#datasongs").load(data, "", function(response, status, xhr) {
alert ("status is: " + status);
});
}
});
}
executeGetList检索一些数据,设置寻呼机 (sfDoctrinePager) 并返回一个渲染部分,如:
return $this->renderPartial('song/listSongSearchLite', 
array('roster' => $this->roster,
'pagerSongs' => $this->pagerSongs));

在ajax调用的 success中回调函数,我检索发送的数据,这正是我想要的。但是,当我执行 .load() 时jquery 函数,我收到 404 错误。

该错误是因为 symfony 试图找到以 ajax 调用生成的 html 开头的路由。返回的数据以
<table><thead><tr

symfony 日志是:
Oct 28 23:32:05 symfony [info] {sfWebResponse} Send status "HTTP/1.1 200 OK"
Oct 28 23:32:05 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} Configuration 12.69 ms (8)
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} Factories 58.78 ms (1)
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} Action "genre/getList" 705.05 ms (1)
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} Database (Doctrine) 0.18 ms (24)
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} Partial "song/_listSongSearchLite" 222.21 ms (1)
Oct 28 23:32:05 symfony [info] {sfWebDebugLogger} View "None" for "genre/getList" 0.02 ms (1)
Oct 28 23:32:05 symfony [info] {sfWebResponse} Send content (8801 o)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signin" (/guard/login)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signout" (/guard/logout)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "apply" (/user/new)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "reset" (/user/password-reset)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "resetRequest" (/user/reset-request)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "resetCancel" (/user/reset-cancel)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "validate" (/user/confirm/:validate)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Connect sfRoute "settings" (/user/settings)
Oct 28 23:32:07 symfony [info] {sfPatternRouting} Match route "default_index" (/:module) for /<table><thead><tr with parameters array ( 'module' => '<table><thead><tr', 'action' => 'index',)
Oct 28 23:32:08 symfony [info] {sfFrontWebController} Action "tabletheadtr/index" does not exist
Oct 28 23:32:08 symfony [err] {sfError404Exception} Action "tabletheadtr/index" does not exist.
Oct 28 23:32:08 symfony [info] {sfWebResponse} Send status "HTTP/1.1 404 Not Found"
Oct 28 23:32:08 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
Oct 28 23:32:08 symfony [info] {sfWebDebugLogger} Configuration 8.27 ms (5)
Oct 28 23:32:08 symfony [info] {sfWebDebugLogger} Factories 63.62 ms (1)

任何帮助将不胜感激。

莫希特

最佳答案

在代码中,您有:

success: function(data){
$("#datasongs").load(data, "", function(response, status, xhr) {
alert ("status is: " + status);
});

传递从 .ajax() 返回的数据的地方作为新请求的 URL .load() .好像不太对
.load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] )

似乎您正试图将返回的数据放入 $("#datasongs") .为此,您使用函数 .html()不是 .load() .

关于Symfony 1.4 中的 Ajax 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7936084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com