Button click triggering XMLHttpRequest not functioning properly due to null

I am facing an issue with my webpage. When I click on a certain section labeled as "trigger," it is supposed to print the content in the "#content" page. However, I want it to redirect back to the "home" section when I click on the "BACK" button that appears on the displayed page. Unfortunately, this feature does not seem to be working. Can you please help me identify where I might be going wrong?

index.php

<div class="app-content content" id="content">
<?php require 'home' ?></div>

home.php

<div id="kasaButton">
    <a type="button" href="#" data-target="contact"> Contact</a>
    <a type="button" href="#" data-target="gallery"> Gallery</a>
</div>

<div class="card">
<table class="datatables-basic table">
    <thead>
    <tr>
        <th>İD</th>
        <th>NAME</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>İD</td>
        <td>NAME</td>
    </tr>
    </tbody>
</table>
</div>

gallery

<div class="card-body">
    <form action="" method="post">
        <input type="text" class="form-control" placeholder="Cari Adı" value=""/>
        <button id="save" type="submit">SAVE</button>
        <button id="back" type="button">BACK</button>
    </form>
</div>

 $(document).ready(function () {
        var trigger = $("#kasaButton a"),
            container = $("#content");

        trigger.on("click", function () {
            var $this = $(this)
            target = $this.data('target');
            container.load(target);
            return false;
        });
    });

$(document).ready(function () {
        $("#back").on("click", function () {
            $("#content").load('home');
        });
    })

Answer №1

To include a div with the id of "content", you can follow this example from gallery.php:

<div class="card-body">
    <form action="" method="post">
        <input type="text" class="form-control" placeholder="Search Name" value=""/>
        <button id="save" type="submit">SAVE</button>
        <button id="back" type="button">BACK</button>
    </form>
</div>

<div id="content"></div>

<script>
$(document).ready(function () {
        var trigger = $("#kasaButton a"),
            container = $("#content");

        trigger.on("click", function () {
            var $this = $(this)
            target = $this.data('target');
            container.load(target);
            return false;
        });
    });

$(document).ready(function () {
        $("#back").on("click", function () {
            $("#content").load('home.php');
        });
    })
</script>

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

The bottom margin of the last element does not affect the size of its container

I'm curious as to why the margin-bottom of .content-b isn't affecting the height of the .container. .container { background: grey; } .content-a, .content-b { height: 100px; border: 1px solid red; margin-bottom: 100px; } <div class= ...

CSS Flexibility in Action

Presently, my tab bar has a fixed look as shown here: https://codepen.io/cdemez/pen/WNrQpWp Including properties like width: 400px; etc... Upon inspecting the code, you'll notice that all the dimensions are static :-( Consequently, I am encountering ...

What is the process for determining the area of the section?

Take a look at this page as an example - scrolling down on responsive devices reveals related navigation areas which I aim to change with scrollspy (affix fixed navigation). Having a bootstrap navbar, when on the corresponding section of the navbar while u ...

Is it possible to use Ajax to prompt a pop-up window for basic authentication when logging in?

While attempting to access the reed.co.uk REST web API in order to retrieve all related jobs, I am encountering an issue. Despite passing my username and password, a popup window keeps appearing when I call the URL. The alert message displayed reads: i ...

Can the JavaScript code be altered within the client's browser?

So, I'm using JQuery Validator on my webform to validate form data. However, I haven't added any validation on the server side. I'm curious if it's possible for a user to modify the code and bypass my validations in their browser. If th ...

Utilizing Laravel to send an ajax request to a controller

I am encountering a strange issue with the response from my ajax request. The controller's method below is supposed to return an ID: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; //use App\Http&bsol ...

What could be causing my popup window to not display on top of all other HTML elements?

.box { width: 40%; margin: 0 auto; padding: 35px; border-radius: 20px/50px; background-clip: padding-box; text-align: center; display: inline-block; } .button { font-size: 1em; padding: 10px; color: #222; border: 2px solid #06D85F; ...

Looking for assistance with extracting only numerical values from a webpage using Selenium in Python

Website Elements <td style="font-size:20px;font-family:LucidaGrande,tahoma,verdana,arial,sans-serif;padding:10px;background-color:#f2f2f2;border-left:1px solid #ccc;border-right:1px solid #ccc;border-top:1px solid #ccc;border-bottom:1px solid #ccc; ...

Display items in a not predetermined order

Despite its simplicity, I am struggling to get this working. My aim is to create a quiz program using JavaScript. Here is the basic structure: <ul> <li>option1</li> <li>option2</li> <li>option3</li> </ul> &l ...

Tips for creating a hover effect on an icon within a CSS grid

I've just started learning to code and wanted to create a component for previewing/displaying a project I'm working on. I've been attempting to add a hover effect to my links such as the GitHubIcon and LaunchIcon, but so far, it's not w ...

Challenges arising when transferring data from Django to HTML

I am trying to calculate the sum of elements in lista[] which consists of decimal numbers, but I keep getting this error message: lista[] is composed of decimal numbers ValueError at / argument must be a sequence of length 3 This is my code : views.py ...

Adjust CSS classes as user scrolls using skrollr

I am currently facing an issue with the prinzhorn/skrollr plugin when trying to use removeClass/addClass on scroll function. I have attempted to find a solution but unfortunately, nothing has worked for me. <li class="tab col s3"><a data-800="@cl ...

Inserting an additional element through a button click

I have come across an issue that I need help with: On this particular page (please note it is not my own, just using it as an example) you can see a standard expandable menu listed under non-accordion (standard expandable menu) What I am wondering is ...

Prevent selection of any dates before the most recent 2 days on the jQuery datepicker

Is there a way to restrict the date-picker from displaying past dates, except for the last 2 dates? <link href="Content/jquery-ui-1.8.23.custom.css" rel="stylesheet" /> <script src="Scripts/jquery-1.8.1.min.js"></script> <script src=" ...

Unable to automate the selection of a dropdown menu using Selenium WebDriver

I am currently utilizing http://www.makemytrip.com/ This is the HTML code. <div class="mrgnBot30 clearFix"> <span class="watch_icn flL"></span> <div class="widget_inner clearFix suggest_me padBot15 flL"> <h3 class="clearFix has ...

Share identification but display the label

I'm currently utilizing the jQuery plugin Tag-It for managing auto-suggestion and tagging functionalities. The data retrieval through an Ajax call is operating smoothly. Right now, the data is being fetched in the following format: {"itemID":"ItemNa ...

Is there a way to efficiently load POST data into SimpleXML?

I am facing a challenge in posting XML data from a textarea input to PHP for parsing and generating an output table. Despite trying various methods, none seem to be yielding results. My current approach is as follows: jQuery('#btnRegistrarXML' ...

CodeIgniter encountering a persistent issue with AJAX that causes it to reload the

Whenever I attempt to send an AJAX request with jQuery, the response I receive is the HTML of the same page! Here's a live preview (editing not available as I am currently fixing it) Below are the files: Main controller: Class Main extends Controll ...

Initiate an Ajax request solely for the elements currently visible on the screen

I am currently facing an issue that requires a solution. Within our template, there are multiple divs generated with the same classes. Each div contains a hidden input field with the ID of the linked target site. My task is to utilize this ID to make aja ...

Prevent clicking during transitions with Jquery Cycle

Is there a way to prevent multiple transitions by restricting the clicking of the next button? Thank you! ...