Troubleshooting JQuery AJAX HTML Problems in Google Chrome and Firefox

I'm facing an issue with my code and I'm not sure what to do. It works perfectly on Internet Explorer, but when I try to open it on Chrome or Mozilla, the links in my menu don't work! I click on them but nothing happens. Can someone please help me?

(I know my CSS code is fine because it's an old one that I've used before)

Here is the HTML for my menu:


<head>
    <title> Practice 5 </title>
    <meta http-equiv="Content-Type" 
    content="text/html; charset=UTF-8">

    <link rel="stylesheet" type="text/css" href="css/all.css">
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>

    <script type="text/javascript">

       function loadPage(page,menuItem){

            $.ajax({
               url : page,
               cache : false,
               success : function(object,status,response){

                  $("#principal").html(response.responseText);
               }
           });
           $("#menu div").removeClass('active');
           $("#m"+menuItem).addClass('active');
        }


   </script>
</head>



<body>
    <div id="message" style="display:none" title="Hello">
    Welcome to my page!
    </div>


   <div id="area">
        <div id="menu">

            <div id="m1" onClick="javascript:loadPage('about.html',1)">Home</div> 

            <div id="m2" onClick="javascript:loadPage('page4.html',2)">About</div>

           <div id="m3" onClick="javascript:loadPage('help.html',3)">Help</div>

        </div>
        <div id="principal">


        </div>
    </div>
</body>


Answer №1

swap out:

success : function(object,status,response){
                  $("#principal").html(response.responseText);
               }

and replace it with:

success : function(data){
                  $("#principal").html(response.responseText);
               },error:function(xhr, status, error){
                   console.log(xhr.responseText);
               }

Here is the updated and functional code :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script type="text/javascript">
 function carga(pagina,menu){
//alert(pagina);
            $.ajax({
               url : pagina,
               cache : false,
               success : function(data){
                  $("#principal").html(response.responseText);
               },error:function(xhr, status, error){
                   console.log(xhr.responseText);
               }
           });
           $("#menu div").removeClass('bActivo');
           $("#m"+menu).addClass('bActivo');
        }


</script>

</head>

<body>

<div id="mensaje" style="display:none" title="Holaa">
    welcome :3
    </div>


   <div id="area">
        <div id="menu">

            <div id="m1" onClick="carga('acerca.html',1);">Inicio</div> 

            <div id="m2"onClick="carga('pagina4.html',2);">Acerca: </div>

           <div id="m3"onClick="carga('ayuda.html',3);">Ayuda</div>

        </div>
        <div id="principal">


        </div>
    </div>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using AJAX within the $.when function to extract the first character from the returned string

Currently, I am utilizing an AJAX call by using $.when to wait for the completion of that specific ajax request and then continue with processing the subsequent ajax request inside. The code block below demonstrates where the $.when method is being invoke ...

Generating Placeholder Variables Within a v-for Iteration

Encountering a problem with Vue-JS involving v-for loops and v-model properties. I have an array of items: <input v-for="i in list" v-model="i.model" ... (other tags that use i) > </input> Accompanied by some JavaScr ...

Allow the checkbox to only be functional for one use

Toggle the checkboxes between enable and disable based on user's choice to edit or cancel operation. This functionality has been tested on both my Android phone and tablet devices. Upon loading the page, the HTML code appears like this: <div class ...

The Mysteries of Key Codes in JavaScript

I'm curious about the character codes used for keyboards. Recently, I came across an informative article discussing this topic. In particular, I am interested in finding out which key code to use when a user presses both the alt and down arrow keys s ...

Encountering issues with the Sequelize Model.prototype.(customFunction) feature malfunctioning

While attempting to define a customFunction within the Sequelize model, I encountered an error: TypeError: user.getJWT is not a function at User.create.then (/projects/test/a/app/controllers/UserController.js:22:29) Below is the code snippet from ...

What methods are available for transferring information between nodejs and puppeteer?

Recently, I developed a nodejs application that kicks off from index.js. Within index.js, puppeteer is launched and bot.js is injected into a headless-api page using the addScriptTag function. In my implementation, index.js sets a cookie to pass initial v ...

Issues arise when using the "placeholder" attribute within a <p:inputText tag while the inputText is devoid of any value

A current project involves implementing JSF Mojarra 2.3.9.SP02 alongside PrimeFaces 7.0 on Wildfly 17 using the Sapphire template provided by PrimeFaces. However, I've encountered a significant issue with a specific <p:inputText element within my f ...

Updating a CSS file through jQuery is proving to be ineffective

After searching extensively on Stack Overflow and other websites, I have not been able to find a clear answer to my question regarding changing a CSS class (#navbar a) after a specific function is triggered. My understanding of jQuery and JavaScript is lim ...

Error validation for jQuery div dropdown

Can jQuery validation be used to set the required attribute on a Bootstrap styled div dropdown instead of an option/select tag? The tags cannot be changed on this page, and there are multiple div dropdowns. <div class="btn-group"> <button typ ...

Invoke the prototype function through an onclick event after dynamically adding a button

Within my code, I have created two prototype functions named showPopup and buildView. The buildView function is responsible for generating dynamic HTML that includes a button. My intention is to invoke the showPopup function when this button is clicked. Ho ...

Registration and Mapping Interface API

Recently, I have been researching information for an application that we are planning to develop for our chain of stores (approximately 20). Our goal is to reward customers with points when they check-in at our store locations. Additionally, we aim to show ...

Creating a custom function in JavaScript to interact with the `windows.external` object specifically for use

In my current project, I am facing an issue with JavaScript file compatibility across different browsers. Specifically, I have a JavaScript file that calls an external function (from a separate file) using windows.external, like this: windows.external.se ...

Unanticipated commitments fulfilled on the spot

While troubleshooting a setup for managing promise concurrency in handling CPU-intensive asynchronous tasks, I encountered perplexing behavior that has left me puzzled. To regulate the flow, my approach was to initially create an array of Promises and the ...

Flatbuffers does not exist in this context

Currently, I am working on a nodeJs application that involves the use of Google Flat Buffer. After installing flatc on my MacBook Pro, I compiled the schema below: namespace MyAlcoholist; table Drink { drink_type_name: string; drink_company_name: stri ...

Utilize AntiForgeryToken for Accessing WebAPI in Aspnet 5.0 within Xamarin Environment

I am currently facing an issue with accessing a WebAPI that utilizes ValidateAntiForgeryToken. The WebAPI Method I am working with is located within a UserController for testing purposes: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Test(Stri ...

Encountering a problem with the multi-page template structure in jQuery Mobile

As a newcomer to Phonegap, I am utilizing jQuery Mobile and HTML5 for the development of an Android app. The app consists of three pages: the first page, index.html, displays a list of contents; the second page holds text content as well as a header with b ...

AngularJS issue: Unable to reset scope variable

I am facing an issue with a function in my angularJS controller that is triggered on a dropdown option change: Currently, when a default option is selected, the corresponding records from the database are fetched and set to a scope variable. Everything s ...

Finding the exact location of a specific element within a div: tips and tricks

Is there a way to determine the position of an image inside a div when clicked? Here is my HTML code: <div> <p>test</p> <img src='test1.jpg'/> <p>test</p> <p>test</p> <img src=&ap ...

Trigger the function upon successful completion of Stripe Checkout

I have a requirement in my Nodejs/Express API to execute a series of confirmation code once the checkout process is successfully completed in Stripe by the client. Below is the checkout function responsible for handling the checkout phase: // Checkout con ...

Typescript raises an issue regarding a React component's optional prop potentially being undefined

I have a basic React component that looks like this: interface ComponentProperties { onClick?: () => void; } const CustomComponent = (properties: ComponentProperties) => { if (!properties.onClick) { return <></>; } ...