Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:17:10+00:00 2026-05-30T19:17:10+00:00

I have a little problem with jquery mobile. always my page is called this

  • 0

I have a little problem with jquery mobile. always my page is called this function runs.

$(document).bind('pagechange', function () { 
  // peforms ajax operations
})

The problem is that each time my page is viewed it increases the times my ajax is called… example: if the page is viewed 5 times, next time will peform the same ajax request 6 times.

I’m using asp.Net MVC 4.

Multiple ajax requests

Full code:

@{
    //ViewBag.Title = "Consulta";
    Layout = "~/Views/Shared/_LayoutMenu.cshtml";
}
<div class="ui-body ui-body-b" id="test">
    (...) some html code (...)
</div>
<script>        
$(document).bind('pagechange', function () {
    $('#info').css('visibility', 'hidden');

    $('#name').keypress(function (e) {

        if (e.keyCode == 13) {

            var code = $(this)[0].value;

            $.ajax({
                url: '/Consulta/ObterDadosPulseira',
                data: $(this).serialize(),
                success: function (data) {

                    $('#info').css('visibility', 'visible');

                    var info = $('#info')[0];

                    $('#info [id=gridCod]').html(data[0].cod);
                    $('#info [id=gridName]').html(data[0].nome);

                },
                complete: function () { },
                error: function () { alert('error!'); }
            });

            $(this)[0].value = '';
        }
    });
    $('#name').focus();                       
});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:17:11+00:00Added an answer on May 30, 2026 at 7:17 pm

    Normally this happens because you are binding an event handler within another event handler. For instance if you were binding a pagechange event handler inside of a pageshow event handler.

    Also if you want to bind to the page events for a specific page, you can just bind to the data-role="page" element:

    $(document).delegate('#my-page-id', 'pageshow', function () {
        //now `this` refers to the `#my-page-id` element
    });
    

    Update

    I just saw your updated answer with the extra code, and your problem is that you are binding an event handler inside another event handler. Basically each time the pagechange event is firing, a new event handler is bound to the #name element.

    Try this:

    $(document).delegate('#name', 'keypress', function () {
    
        if (e.keyCode == 13) {
    
            var code = this.value;
    
            $.ajax({
                url: '/Consulta/ObterDadosPulseira',
                data: $(this).serialize(),
                success: function (data) {
    
                    $('#info').css('visibility', 'visible');
    
                    var info = $('#info')[0];
    
                    $('#info [id=gridCod]').html(data[0].cod);
                    $('#info [id=gridName]').html(data[0].nome);
    
                },
                complete: function () { },
                error: function () { alert('error!'); }
            });
    
            this.value = '';
        }
    }).bind('pagechange', function () {
        $('#info').css('visibility', 'hidden');
        $('#name').focus();                       
    });
    

    This uses event delegation to bind the event handler to the #name element, this way the event handler will be bound once for all-time.

    Docs for .delegate(): http://api.jquery.com/delegate

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have a little problem with jQuery: $('#form-submit').click(function () { $('#textarea, #name').removeClass('error-state').addClass('normal-state'); var myName
I have a little problem: I don't knwo how to run this jQuery plugin:
I'm making an PhoneGap app using Jquery Mobile, but I have a little problem
i have a little jquery script : $('.product_types > li').click(function() { $(this) .css('backgroundColor','#EE178C') .siblings()
I have a little problem about using jQuery (I really do not know jQuery
I have this little problem, that I cannot figure out which arguments to pass
I have modified jquery mobile a little so a collapsible with data-type=horizontal converts into
I have a little problem with jQuery Tabs. I get it to work well.
I have a little problem with the jQuery UI Stack $('.dra').draggable({ addClasses: false, containment:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.