Не удается прочитать свойство ‘replaceWith’ из null — вызов ajax

Я пытаюсь заменить «Привет, мир!» с «Привет тебе тоже», используя ajax replaceWith. Однако я получаю эту ошибку:

Не удается прочитать свойство ‘replaceWith’ из null

Где я беру неправильный поворот?

ПРИМЕЧАНИЕ: вызов ajax работает с предупреждением (ответом);

index.phtml:

<div id="helloworld">Hello world!</div>

<script type="text/javascript">
jQuery.ajax({
url: "<?php echo $this->getUrl('topperproductqa/index/ajax') ?>",
success: function(response){
$('#helloworld').replaceWith(response);
//alert(response);
}
});
</script>

IndexController.php:

class Topper_ProductQA_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();

return $this;
}

public function ajaxAction ()
{
$response = "Hello to you too";

$json =  json_encode($response);
$this->getResponse()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody($json);
}
}

2

Решение

Я понял, что Magento использует $ на prototype.js, я исправил это с помощью:

(function($) {

$.ajax({
url: "<?php echo $this->getUrl('topperproductqa/index/ajax') ?>",
dataType: "json",
success: function(response){
$("#helloworld").replaceWith(response);
//alert(response);
}
});

})(jQuery);
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector