Issues

ZF-9926: Incorrect html output produced by ajaxLink

Issue Type: Patch Created: 2010-06-01T09:02:58.000+0000 Last Updated: 2011-08-26T09:13:42.000+0000 Status: Resolved Fix version(s): - 1.11.8 (07/Jul/11)

Reporter: Dmitry A Ponomarev (earthperson) Assignee: Kim Blomqvist (kblomqvist) Tags: - ZendX_JQuery

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: - ZF-11597

Attachments: - AjaxLink.php.patch

Description

When 'inline' key are used - html output is incorrect!

This code:

<pre class="highlight">
<?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:

<pre class="highlight">
<a href="/index/delete/id/57">[Delete]</a>

Just replace this code in AjaxLink.php:

<pre class="highlight">
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):

<pre class="highlight">
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:

<pre class="highlight">
<a href="#" title="edit"></a>

Which gets interpreted in FF5 as:

<pre class="highlight">
<a href="#" title="edit">
</a>

The quotes aren't properly escaped.

The old version generated:

<pre class="highlight">
<a href="#" title="edit">
</a>

unchanged view script code used for both versions:

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

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:

<pre class="highlight">
<a href="#" title="edit">
</a>

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts