locked
Display Ajax Results RRS feed

  • Question

  • User1028731656 posted

    I have this JQuery code shows the results for a split second and disappear. What I am doing wrong?

    $(function () {
    
        $("#main_rent_btn").click(function () {
    
            $.ajax({
                url: '/Home/GetRent',
                contentType: 'application/html; charset=utf-8',
                type: 'GET',
                dataType: 'html',
                cache: false,
                beforeSend: function () {
                    $('#loading').show();
                }
            })
              .success(function (result) {
    
                  $("#rent_results").html(result);
                  $('#loading').hide();
              }).
                error(function (xhr, status) {
                alert(status);
           })
    
        });
    });

    Tuesday, August 5, 2014 12:48 AM

Answers

  • User1918509225 posted

    Hi terminatorar,

    I have tested in your code in my compute, I added a button, and removed code about dialog,which worked very well:

    <script type="text/javascript">
     
        $(function () {
            $("#test").click(function () {
    
                $.ajax({
                    url: '/Home/GetRent',
                    contentType: 'application/html; charset=utf-8',
                    type: 'GET',
                    dataType: 'html',
                    cache: false,
                    beforeSend: function () {
                         //$('#loading').show();
                    }
                })
            .success(function (result) {
                $("#rent_results").html(result);
    //$('#loading').hide();
    }). error(function (xhr, status) { alert(status); }) }) }) </script> <input type="button" id="test" value="tst" /> <div id="rent_results"> </div>

    I suggest you first try to remove code Below ,see if it can work:

      // $('#loading').show();
      //$('#loading').hide();

    If you still have problem, I  suggest you put your html code ,so I can   reproduce your  problem in my computer.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 6, 2014 4:13 AM

All replies

  • User2103319870 posted

    I have this JQuery code shows the results for a split second and disappear. What I am doing wrong?

    Looks like your button is getting postback and the result is shown and disappear very fast. Try disable the postback on success like given below

    $(function () {
    
        $("#main_rent_btn").click(function () {
    
            $.ajax({
                url: '/Home/GetRent',
                contentType: 'application/html; charset=utf-8',
                type: 'GET',
    	    async: false,
                dataType: 'html',
                cache: false,
                beforeSend: function () {
                    $('#loading').show();
                }
            })
              .success(function (result) {
    
                  $("#rent_results").html(result);
                  $('#loading').hide();
    	      return false;
              }).
                error(function (xhr, status) {
                alert(status);
           })
    
        });
    });

    Tuesday, August 5, 2014 1:12 AM
  • User1918509225 posted

    Hi terminatorar,

    I have tested in your code in my compute, I added a button, and removed code about dialog,which worked very well:

    <script type="text/javascript">
     
        $(function () {
            $("#test").click(function () {
    
                $.ajax({
                    url: '/Home/GetRent',
                    contentType: 'application/html; charset=utf-8',
                    type: 'GET',
                    dataType: 'html',
                    cache: false,
                    beforeSend: function () {
                         //$('#loading').show();
                    }
                })
            .success(function (result) {
                $("#rent_results").html(result);
    //$('#loading').hide();
    }). error(function (xhr, status) { alert(status); }) }) }) </script> <input type="button" id="test" value="tst" /> <div id="rent_results"> </div>

    I suggest you first try to remove code Below ,see if it can work:

      // $('#loading').show();
      //$('#loading').hide();

    If you still have problem, I  suggest you put your html code ,so I can   reproduce your  problem in my computer.

    Best Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 6, 2014 4:13 AM