Good day! Faced a possible problem. I send by clicking on the button, a request to the server on Django. The code works, but for some reason Jquery sends 2 identical requests and accordingly returns 2 identical answers. Here is the jQuery code
$(document).ready(function(){ $( "#exit" ).click(function(){ $('#contentresp').fadeOut("slow").html(""); setTimeout(function(){$("#respwindow").animate({ height: "0%", width:"0%" }, 200 ); $('#menu').fadeIn("slow");},400); $("#respwindow").hide() }) $("[data-v]").click(main_menu) function main_menu(){ $.ajax({ type: "GET", url: "/change_views/", data:{ 'view':$(this).data('v'), }, cache:false, success: function(data){ $("#respwindow").show().animate({ width:"100%" }, 200 ).animate({ height:"100%" }, 200 ); $('#menu').fadeOut("slow"); setTimeout(function(){$('#contentresp').html(data); $('#contentresp').fadeIn("slow")},500); } }); } } ) Here is the urls.py code
from django.conf.urls import url from django.contrib import admin from .views import (base,main_menu,change_views,change_order) urlpatterns = [ url(r'base/$', base, name='base'), url(r'mainmenu/$', main_menu, name='mainmenu'), url(r'change_views/$', change_views, name='change_views'), url(r'change_order/$', change_order, name='change_order'), ] Here is the view.py code
from django.shortcuts import render, render_to_response from django.http import HttpResponse from .models import MySkills # Create your views here. def base(request): title = "Base" context = { "title":title, } return render(request,"base.html",context) def main_menu(request): title = "Main menu" context = { "title":title, } return render(request,"main.html",context) def change_order(request): if request.is_ajax(): name_p = request.GET.get('name_p') stage = request.GET.get('stage') dateStat = request.GET.get('dateStat') context = {"name_p":name_p,"stage":stage,"dateStat":dateStat} return render_to_response("page/items/change_order.html",context) def change_views(request): if request.is_ajax(): get_view =request.GET.get('view') address = get_view.replace(" ","_") if get_view == "My skills": lang = MySkills.objects.filter(skill_type="PL") fw = MySkills.objects.filter(skill_type="FW") sklAp = MySkills.objects.filter(skill_type="AS") anSkl = MySkills.objects.filter(skill_type="AnS") context = {"lang": lang,"fw": fw, "sklAp": sklAp, "anSkl": anSkl, "Vtitle":get_view} elif get_view == "My projects": context = {"Vtitle":get_view} else: title = get_view answer = 'I am Ajax!' context = {'title':title,'answer':answer} return render_to_response('page/About_me.html',context) return render_to_response('page/'+address+'.html',context) Html home page.
{% extends "base.html" %} {% load staticfiles %} {% block head %} <link rel="stylesheet" href="{% static 'css\my_css\maincss.css'%}"> {% endblock head %} {% block content %} <div> <div id="menu" class="outer" style="height:100%; width: 100%; position:absolute;z-index:0"> <div class="inner" style=""> {% include "page/menu.html"%} </div> </div> <div id="respwindow" class="windowResponse"> <span id="exit" class="glyphicon glyphicon-remove size-36" style="position:relative; float:left;color:red;z-index:40"></span> <div id="contentresp"> </div> {% block scripts %} <script src="{% static 'js\my_js\ajax_request.js' %}"></script> {% endblock %} </div> base.html wrapper
{% load staticfiles %} <!DOCTYPE html> <html lang="en" style="height:100%"> <head> <meta charset="UTF-8"> <title>Document</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!-- Latest compiled and minified JavaScript --> <script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <!--My css--> <link rel="stylesheet" href="{%static 'css\oth_css\stars.css' %}"> <link rel="stylesheet" href="{%static 'css\my_css\fontsstyle.css' %}"> <link rel="stylesheet" href="{%static 'css\my_css\basestyle.css' %}"> {% block head %} {% endblock %} <style> .outer:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; } .inner { display: inline-block; vertical-align: middle; margin-left: -0.35em; } .outer { text-align: center; } </style> </head> <body style="height:100%; width: 100%; overflow:hidden"> <div id=#title> {% block content %} {% endblock %} </div> {% block scripts %} {% endblock %} <script src="{%static 'js\oth_js\space_bg.js'%}"></script> </body> </html> So it should be? Or is there an error in the code? All code can be seen on my github https://github.com/Lairion/Portfolio

main.htmlfilemain.htmlthescriptblock is located inside thecontentblock. As a result of the substitution in thebase.htmlscriptblock will be included two times. Then I think you understand) - Nikmoon