Reputation: 23
I am using symfony 1.4 and am trying to paginate my search results using Ajax calls but am having difficulties.
My ajax call is made to an action (executeGetList) where I pass in the page parameter. This is how I make the ajax call:
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
retrieves some data, sets up the pager (sfDoctrinePager) and return a renderpartial like:
return $this->renderPartial('song/listSongSearchLite',
array('roster' => $this->roster,
'pagerSongs' => $this->pagerSongs));
In the ajax call's success
call back function, I retrieve the data sent and it is exactly what I want. However, when I perform the .load()
jquery function, I get a 404 error.
The error is caused because symfony is trying to find a route which starts with the html generated by the ajax call. The data returned starts with
<table><thead><tr
The symfony logs are:
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)
Any help will be appreciated.
Mohit
Upvotes: 2
Views: 1091
Reputation: 4395
In the code you have:
success: function(data){
$("#datasongs").load(data, "", function(response, status, xhr) {
alert ("status is: " + status);
});
where you pass the data returned from the .ajax()
as the url for the new request .load()
. Doesn't seem right.
.load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] )
It seems like you are trying to put the data returned inside $("#datasongs")
. For that you use the function .html()
not .load()
.
Upvotes: 3