简体   繁体   中英

Magento adminhtml: “sendMail” is not a function

I'm developing a really custom admin page for Magento (I know I'm a bit out of the usual way to develop Magento's extensions). I have a function called sendMail that, when a button is clicked, calls a controller that sends a mail. Everything is fine the first time I run this (so I know it's not a routing problem, but a javascript one), but from the second one I get the error Uncaught TypeError: sendMail is not a function .

Here is my code:

Button piece (this is added to the page through javascript)

"<td><button onclick='sendMail("+"\"<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/sendBrochure/send/'); ?>"+"?isAjax=true"+"&id="+resultLog[i].id+"\")'>Send brochure</button></td>";

sendMail function :

function sendMail(link){
    sendMailPath = link;
    sendMail = new XMLHttpRequest();
    sendMail.open("get", sendMailPath, true);
    sendMail.setRequestHeader("Content-type","application/x-www-form-urlencoded");

    sendMail.send();
}

Do you have any clue about why this code works only the first time?

As my comment fixed the problem, I am going to post it as an answer:

Just a guess, but: does it help when you try to change the "sendMail" variable to something different inside your sendMail function?

Actually I thought that you could use local variables with names as much as you like, since local names should only be available inside the function and be removed from the stack when the block is left. Maybe someone can explain?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM