jQuery ignoring the slashes /

1

I have the following code of button :

<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('View all items in your shopping cart')) ?>" class="button btn-inline-ver-carrinho" onclick="setLocation('<?php echo $this->getUrl('checkout/cart') ?>')"><span><span>Ver Carrinho</span></span></button>

In event% with% of this onclick , it returns me a full button , but when I use this code by jQuery using url as follows:

$j('#mini-cart').append("<button type='button' title='<?php echo Mage::helper('core')->quoteEscape($this->__('View all items in your shopping cart')) ?>' class='button btn-inline-ver-carrinho' onclick='setLocation('<?php echo $this->getUrl("checkout/cart") ?>')'><span><span>Ver Carrinho</span></span></button>");

The same code returns me in .append() to onclick , but without the slashes (/) and executing this code normally without using jQuery, url is shown correctly.

By url , it returns me the following: php

By onclick="setLocation("localhost/checkout/cart")" , it returns me the following:

onclick="setLocation("localhost  checkout  cart')'
    
asked by anonymous 15.12.2017 / 17:39

1 answer

1

Explanation

Apparently your problem is separating into variables to avoid strings with single and double multiple-string strings.

So I recommend using jQuery dynamic element creation and set the attributes of it in the hand, as below:

Code

function setLocation(href){
  document.location.href = href;
}

var btn = $('<button>'),
    spn = $('<span>'),
    str = 'View all items in your shopping cart',
    cls = 'button btn-inline-ver-carrinho',
    evt = "setLocation('<?php echo $this->getUrl(\"checkout/cart\") ?>')";
    
$(btn).attr({
  title: str,
  class: cls,
  onclick: evt
});

$(spn).html('<span>Ver Carrinho</span>');
$(btn).append(spn);


$('#mini-cart').append(btn);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id=mini-cart >
</div>

Observations

I do not own your php so please replace where I put it fixed by the php code you have that generates what you need.

    
15.12.2017 / 18:04