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 7961005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:54:41+00:00 2026-06-04T04:54:41+00:00

i am using MVC and my design for my website is that there is

  • 0

i am using MVC and my design for my website is that there is header and body and footer,
every page in my website will have the same header and the same footer, but with different body

and for ever page there is a JS file contains the jquery calls

and for many many pages when it is opening, jquery call works and get data from database using ajax and put that data in that page

my question is : sense the jquery calls begins with $(document).ready, so when i open any page, all the jquery call starts, i don’t want that, but i want just the jquery for that page which is opening to be loaded

example

this jquery just for a page

$(document).ready(function(){
    $.getJSON("http://localhost/Mar7ba/Cell/getAllCountries/TRUE",function(data){
        var select = $("#countrySelector");
        var options = '';
        for(var i=0;i<data.length;i++){
            options += "<option>"+data[i]+"</option>";
        }
        select.html("<option>Select Source</option>"+options);
    });
});

and this jquery for another page , but it is loaded when i load the first page

$(document).ready(function(){
        $.getJSON("http://localhost/Mar7ba/Type/getAllTypes/TRUE",function(data){
            var options = '';
            options+="<option>Select Type</option>";
            for(var i=0;i<data.length;i++){
                options += "<option>"+data[i]+"</option>";
            }
            $("#addPlace #apTypeSelect").html(options);
        });
    });
  • 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-06-04T04:54:42+00:00Added an answer on June 4, 2026 at 4:54 am

    Test for the existence of the elements you’re operating on, before you fire off the AJAX method. For instance, in your first example:

    $(document).ready(function(){
        var select = $("#countrySelector");
        if (select.length) { // must test .length; 'select' always exists even if it's empty
            $.getJSON("http://localhost/Mar7ba/Cell/getAllCountries/TRUE",function(data){
                var options = '';
                for(var i=0;i<data.length;i++){
                    options += "<option>"+data[i]+"</option>";
                }
                select.html("<option>Select Source</option>"+options);
            });
        }; // end if
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm planning to design simple website using ASP.NET MVC new technology. Many concepts are
I have read a lot about MVC design pattern, but some of the things
i have a website that will have customized designs, depending on what store was
I have two design options to go ahead with when using MVC and NHibernate
I'm using MVC 3 and Razor. I have a page where you can create
This is an ASP.NET MVC website. Following domain driven design, we have a service
I have just started using and am falling in love with MVC design pattern.
I am creating a simple application using the MVC design pattern where my model
Im using MVC-Viewmodel, EF Model first on my project. I have a foreach loop
I'm using MVC, I've got a search page, and I want to pass multiple

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.