Unable to display returned value from php called by ajax

Here is the function.: Where i try to call available.php and it returns an html . I try to append that returned result on the check label. I am getting the image but not able to see the result text.

  <span class="check"  ></span> <br/>
<p> </p>


$("button").click(function () {
    $('.check').show();
    $('.check').fadeIn(400).html('<img src="image/ajax-loader.gif" /> ');

    var pincode = $("#pincode").val();


    $.ajax({
        type: "POST",
        url: "available.php",
        data: {
            'pincode': pincode
        },
        cache: false,
        success: function (result) {
            var result = result;
            if (result == '') {
                $('.check').html('<img src="image/error.png" /> This pincode is not          valid');

                $('.check').append(result);

                $(".check").removeClass("red");
                $('.check').addClass("green");
                $(".pincode").removeClass("yellow");
                $(".pincode").addClass("white");
            }
        }
    });
});

Php code:

  <?php
   echo ' ';
  ?>

Answers


Your code is in the following if statement

if (result == '') {
    // all your code is here
}

and you're returning

echo ' ';

so the code never runs as it's not an empty string, it's a space, remove the if statement

and then there's

var result = result;

remove that line, it makes no sense!


Need Your Help

JavaScript pre-emptive programming?

javascript

I want a similar effect to the following:

Scheduled data updates on Android Wear

android-wear

I'd like some high-level input on how I'm approaching a watch face I'm building as a teaching tool. It's quite simple - grabbing trending topics from Twitter once an hour and displaying them on the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.