Closed (fixed)
Project:
Fivestar
Version:
5.x-1.3
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Mar 2007 at 05:34 UTC
Updated:
11 May 2007 at 12:25 UTC
fivestar_vote() generates the response to an AJAX request when a vote is made, but doesn't set the mime type for the content of the response. Because of this, I ran into an issue with jquery in that although the response was received from the server, it wasn't interpreted as XML, so the values weren't parsed by jquery's selectors. See http://jquery.com/pipermail/discuss_jquery.com/2006-October/013216.html
The following changes force the mimetype and ensure the output is valid XML by adding a root element.
--- all/modules/fivestar/fivestar.module (revision 3708)
+++ all/modules/fivestar/fivestar.module (working copy)
@@ -60,7 +60,7 @@
if (count($result)) {
$output = '';
$output .= '<?xml version="1.0" encoding="UTF-8"?>';
- $output .= '<result>';
+ $output .= '<xml><result>';
foreach ($result as $data) {
$output .= '<'. $data->function .'>' . $data->value . '</'. $data->function .'>';
}
@@ -70,12 +70,12 @@
$output .= '<value>' . $value . '</value>';
$output .= '<type>' . $type . '</type>';
$output .= '<id>' . $cid . '</id>';
- $output .= '</vote>';
+ $output .= '</vote></xml>';
}
else {
$output = 'false';
}
-
+ header("Content-type: application/xhtml+xml");
exit($output);
}
I discovered this when trying to use the data passed by the fivestarResult() javascript hook.
Comments
Comment #1
quicksketchInteresting. I wonder if this is why IE can't properly use the $() function on the result (http://drupal.org/node/110758)? I'll test and see :)
Comment #2
quicksketchFantastic! This patch combined with the patches from #110758 finally, really fixed ajax request for all browsers. Thank you so much for pointing this out! Note, that I set the Content-Type to "text/xml", per the jQuery documentation: http://docs.jquery.com/Ajax. The return value is now much more consistent and functional across browers. Thanks again :)
Comment #3
killes@www.drop.org commented