I want to check customer email is already exist or not using ajax prototype. I tried lots of things but it is not working. I write my code like this.

<script type="text/javascript">
            var dataForm = new VarienForm('form-validate', true);
            Validation.add('validate-emaila', 'Email already exist', function(v) {
    var url = '/customer/account/checkEmail/email?email=' + encodeURIComponent(v);
    var ok = false;
    new Ajax.Request(url, {
        method: 'get',
        asynchronous: false,
        onSuccess: function(transport) {
            var obj = response = eval('(' + transport.responseText + ')');
            validateTrueEmailMsg = obj.status_desc;
            if (obj.ok === false) {
                Validation.get('validate-email').error = validateTrueEmailMsg;
                ok = false;
            } else {
                ok = true; /* return true or false */
        onFailure: function(){ alert('something wrong') },
        onComplete: function() {
            if ($('advice-validate-email-email')) {
            if ($('advice-validate-email-email_address')) {
            if ($('advice-validate-email-billing:email')) {
            if ($('advice-validate-email-shipping:email')) {
            if ($('advice-validate-email-_accountemail')) {
    return ok;


I called a function In accountcontroller

public function checkEmailAction()
      $bool = 0;
      $email = $this->getRequest()->getParam('email');
      $customer = Mage::getModel('customer/customer');
      if ($customer->getId()) {
      $bool = 1;


I am getting wrong response from php function. it is returning full html like this. instead of 0 or 1.

<!DOCTYPE html>

<!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7" style="background:url( no-repeat center 0 #fbfbfb;background-attachment:fixed;"><![endif]-->

<!--[if IE 7]><html class="lt-ie9 lt-ie8 style="background:url( no-repeat center 0 #fbfbfb;background-attachment:fixed;"><![endif]-->

<!--[if IE 8]><html class="lt-ie9 style="background:url( no-repeat center 0 #fbfbfb;background-attachment:fixed;"><![endif]-->

<!--[if IE 9]><html class="ie9 style="background:url( no-repeat center 0 #fbfbfb;background-attachment:fixed;"><![endif]-->

<!--[if gt IE 9]><!--><html class="" style="background:url( no-repeat center 0 #fbfbfb;background-attachment:fixed;"><!--<![endif]-->

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Customer Login  | Lincraft</title>
<meta name="description" content="" />
<meta name="keywords" content="" />

<link rel="stylesheet" type="text/css" href="" media="all" />

            <div class="page">

<div class="header-container">
    <div class="header-outer">
                <div class="header">
            <div class="branding">
                                    <a href="" title="Lincraft: where ideas come to life" class="logo"><strong>Lincraft: where ideas come to life</strong><img src="" alt="Lincraft: where ideas come to life" /></a>

            <div class="header-right ">
                <div class="header-right-info">
                    <div class="welcome-msg"></div>
                    <div class="account-links"><ul class="links">
                        <li class="first" ><a href="" title="Login" >Login</a></li>
                                <li class=" last" ><a href="" title="Register" >Register</a></li>
                <div class="header-right-cart">
    item 0 show on the front end

<div class="top-cart">

    <div class="block-title">
        <a href="" id="topCartTrigger" class="top-cart-number"><strong><span>0</span> items</strong></a>

            two links that on the header
        <div class="block-title no-items">
            <ul class="cart-links">
                <li><a href="">View Cart</a></li>
                <li><a href="">Check Out</a></li>
        <div id="topCartContent" class="block-content" style="display:none">
            <div class="inner-wrapper">                                         <p class="block-subtitle">
                        <span class="close-btn">Close</span>
                        In my cart                  </p>
                    <p class="cart-empty">
                    You have no items in your shopping cart.                    </p>
<!--/{CART_SIDEBAR_536bebca0e80b1d085b731a445d18480}-->             </div>

        <div id="lcNav" class="clearfix">


I have tried lots of thing but giving same response. Can any one tell me what is wrong in this?

2 Answers 2


I would try returning the json response like this:

$status = "PASS"; 
$jsonStatus = 200;

$info =  array( "status" => $status);

$this->getResponse()->setBody(json_encode($info))->setHttpResponseCode($jsonStatus)->setHeader('Content-type', 'application/json', true);

return $this;

If you set the $status to 504 you will return an error.

  • Thanks for the response, I have tried your solution. but it still returning full html. When i see ajax response in browser console it show that it is going to the called function but not returning correct value. Any other solution you know to solve this. May 2, 2014 at 12:40


  • Hello, welcome on Magento SE. Please try to elaborate your answer and explain why you think this is the best solution. Jul 27, 2015 at 12:01
  • I have used this and its working like charm. I am using Magento 1.9.1
    – Manik
    Jul 27, 2015 at 12:15
  • I'm not questioning your answer, I'm just pointing out the fact that it would be more helpful for the OP or others viewing your answer to have a little bit of explanation rather than a one-liner :p Jul 27, 2015 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.