Zend Framework

Incorrect html output produced by ajaxLink

Details

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:

<a href="/index/delete/id/57" onclick='if(!confirm("Do you really want to delete this item?")) {return false;}$("#progress-bar").show();$.post('/index/delete/id/57', {format:"json"}, function(data, textStatus) { $("#progress-bar").hide();$("#entry-57").hide("slow"); }, 'json');return false;'>[Delete]</a>

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;
        }
  1. AjaxLink.php.patch
    24/Apr/11 12:43 PM
    1 kB
    Kim Blomqvist
  2. AjaxLinkTest.php.patch
    24/Apr/11 12:43 PM
    1 kB
    Kim Blomqvist
  3. ZF-9926-rev2.patch
    15/Jul/11 4:40 PM
    12 kB
    Kim Blomqvist
  4. ZF-9926-rev3.patch
    23/Jul/11 11:59 AM
    11 kB
    Kim Blomqvist

Issue Links

Activity

Hide
Kien added a comment -

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?

Show
Kien added a comment - 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?
Hide
Kim Blomqvist added a comment -

Patch attached.

Show
Kim Blomqvist added a comment - Patch attached.
Hide
Matthew Weier O'Phinney added a comment -

Patch reviewed and applied to both trunk and 1.11 release branch.

Show
Matthew Weier O'Phinney added a comment - Patch reviewed and applied to both trunk and 1.11 release branch.
Hide
Jakob Schumann added a comment - - edited

This patch breaks it for me (Using ZF 1.11.9 for ZF + ZendX):

HTML generated by ajaxLink with this patch:

<a href="#" title="edit" onclick='$.get("/translation/index/edit/id/2839", {}, function(data, textStatus) { $('#translation_2839').html(data); }, "html");return false;'

Which gets interpreted in FF5 as:

<a false;'="" "html");return="" },="" #translation_2777').html(data);="" onclick="$.get(&quot;/translation/index/edit/id/2777&quot;, {}, function(data, textStatus) { $(" title="edit" href="#">

The quotes aren't properly escaped.

The old version generated:

<a onclick="$.get('/translation/index/edit/id/2818', {}, function(data, textStatus) { $('#translation_2818').html(data); }, 'html');return false;" title="edit" href="#">

unchanged view script code used for both versions:

echo $this->ajaxLink(
                            $str,
                            BASE_URL."translation/index/edit/id/".$id,
                            array(
                                'update' => '#translation_'.$id,
                                'inline' => true,
                                'title' => 'edit',
                            )
                        );
Show
Jakob Schumann added a comment - - edited This patch breaks it for me (Using ZF 1.11.9 for ZF + ZendX): HTML generated by ajaxLink with this patch:
<a href="#" title="edit" onclick='$.get("/translation/index/edit/id/2839", {}, function(data, textStatus) { $('#translation_2839').html(data); }, "html");return false;'
Which gets interpreted in FF5 as:
<a false;'="" "html");return="" },="" #translation_2777').html(data);="" onclick="$.get(&quot;/translation/index/edit/id/2777&quot;, {}, function(data, textStatus) { $(" title="edit" href="#">
The quotes aren't properly escaped. The old version generated:
<a onclick="$.get('/translation/index/edit/id/2818', {}, function(data, textStatus) { $('#translation_2818').html(data); }, 'html');return false;" title="edit" href="#">
unchanged view script code used for both versions:
echo $this->ajaxLink(
                            $str,
                            BASE_URL."translation/index/edit/id/".$id,
                            array(
                                'update' => '#translation_'.$id,
                                'inline' => true,
                                'title' => 'edit',
                            )
                        );
Hide
Jakob Schumann added a comment -

Applied patch breaks HTML for generated JS code with nested quotes

Show
Jakob Schumann added a comment - Applied patch breaks HTML for generated JS code with nested quotes
Hide
Kim Blomqvist added a comment -

Applied patch breaks HTML for generated JS code with nested quotes

Jakob - I will look into this

Show
Kim Blomqvist added a comment -
Applied patch breaks HTML for generated JS code with nested quotes
Jakob - I will look into this
Hide
Kim Blomqvist added a comment -

Patch rev2 attached. Jakob, could you please test?

Show
Kim Blomqvist added a comment - Patch rev2 attached. Jakob, could you please test?
Hide
Jakob Schumann added a comment -

With the patch rev2 it works, output for my testcase is:

<a href="#" title="edit" onclick='$.get("/translation/index/edit/id/2818", {}, function(data, textStatus) { $("#translation_2818").html(data); }, "html");return false;'>

Looks good, thanks, hope for an update soon, the monthly bug hunt shouldn't be far away

Show
Jakob Schumann added a comment - With the patch rev2 it works, output for my testcase is:
<a href="#" title="edit" onclick='$.get("/translation/index/edit/id/2818", {}, function(data, textStatus) { $("#translation_2818").html(data); }, "html");return false;'>
Looks good, thanks, hope for an update soon, the monthly bug hunt shouldn't be far away
Hide
Kim Blomqvist added a comment - - edited

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.

Show
Kim Blomqvist added a comment - - edited 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.
Hide
Pádraic Brady added a comment -

Patch applied in r24400

Show
Pádraic Brady added a comment - Patch applied in r24400

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: