ZF-9926: Incorrect html output produced by ajaxLink
Description
When 'inline' key are used - html output is incorrect!
This code:
<?php echo $this->ajaxLink(
'[Delete]',
$this->url(array('action' => 'delete', 'id' => $entry->id)),
array(
'dataType' => 'json',
'noscript' => true,
'beforeSend' => 'if(!confirm("Do you really want to delete this item?")) {return false;}$("#progress-bar").show();',
'complete' => '$("#progress-bar").hide();$("#entry-' . $entry->id . '").hide("slow");',
'inline' => true
),
array('format' => 'json')
) ?>
produces:
[Delete]
Just replace this code in AjaxLink.php:
switch($requestHandler) {
case 'GET':
$js[] = sprintf("%s.get('%s', %s, function(data, textStatus) { %s }, '%s');return false;",
$jqHandler, $url, $params, implode(" ", $callbackCompleteJs), $options['dataType']);
break;
case 'POST':
$js[] = sprintf("%s.post('%s', %s, function(data, textStatus) { %s }, '%s');return false;",
$jqHandler, $url, $params, implode(" ", $callbackCompleteJs), $options['dataType']);
break;
}
on this (it solves the problem):
switch($requestHandler) {
case 'GET':
$js[] = sprintf("%s.get(\"%s\", %s, function(data, textStatus) { %s }, \"%s\");return false;",
$jqHandler, $url, $params, implode(" ", $callbackCompleteJs), $options['dataType']);
break;
case 'POST':
$js[] = sprintf("%s.post(\"%s\", %s, function(data, textStatus) { %s }, \"%s\");return false;",
$jqHandler, $url, $params, implode(" ", $callbackCompleteJs), $options['dataType']);
break;
}
Comments
Posted by Kien (vitaminb) on 2011-02-28T23:41:02.000+0000
I have the same problem like in this article "http://zend-framework-community.634137.n4.nabble.com/jQuery-Ajax-link-inside-container-how-to-make-this-td663656.html" my ajax link does not work inside container (called by another ajaxlink). Could someone help me?
Posted by Kim Blomqvist (kblomqvist) on 2011-04-24T12:43:59.000+0000
Patch attached.
Posted by Matthew Weier O'Phinney (matthew) on 2011-07-05T15:03:00.000+0000
Patch reviewed and applied to both trunk and 1.11 release branch.
Posted by Jakob Schumann (j-schumann) on 2011-07-15T11:55:32.000+0000
This patch breaks it for me (Using ZF 1.11.9 for ZF + ZendX):
HTML generated by ajaxLink with this patch:
Which gets interpreted in FF5 as:
The quotes aren't properly escaped.
The old version generated:
unchanged view script code used for both versions:
Posted by Jakob Schumann (j-schumann) on 2011-07-15T11:59:05.000+0000
Applied patch breaks HTML for generated JS code with nested quotes
Posted by Kim Blomqvist (kblomqvist) on 2011-07-15T13:17:42.000+0000
bq. Applied patch breaks HTML for generated JS code with nested quotes
Jakob - I will look into this
Posted by Kim Blomqvist (kblomqvist) on 2011-07-15T16:40:51.000+0000
Patch rev2 attached. Jakob, could you please test?
Posted by Jakob Schumann (j-schumann) on 2011-07-20T09:20:33.000+0000
With the patch rev2 it works, output for my testcase is:
Looks good, thanks, hope for an update soon, the monthly bug hunt shouldn't be far away ;)
Posted by Kim Blomqvist (kblomqvist) on 2011-07-23T11:59:51.000+0000
I noticed that HtlmElement view helper had some quote handling for event attributes. Unfortunately it didn't do the job. Although the revision 2 of the patch included here works for Jakob now, similar issues may occur in future. Thus I have made a new revision of this patch. The new revision depends on ZF-11597.
Posted by Pádraic Brady (padraic) on 2011-08-26T09:13:42.000+0000
Patch applied in r24400