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

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?

Patch attached.

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

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:


          echo $this->ajaxLink(
                            $str,
                            BASE_URL."translation/index/edit/id/".$id,
                            array(
                                'update' => '#translation_'.$id,
                                'inline' => true,
                                'title' => 'edit',
                            )
                        );

Applied patch breaks HTML for generated JS code with nested quotes

bq. Applied patch breaks HTML for generated JS code with nested quotes

Jakob - I will look into this

Patch rev2 attached. Jakob, could you please test?

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 ;)

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.

Patch applied in r24400