Problems with loading . js and . css into external files . php

Asked

Viewed 109 times

0

I have an application that is presenting a problem that had never happened before, recently I started using Javascript to load content without refresh using ajax, but this caused a problem. Every external file. php which is called eque needs the finished jquery.js not working, the only way it works is if I call jquery.js again in the external file. php, only this ends up causing the jquery.js that the menu uses, called in index, stop working, making the menu without action and locking the scrollbar. What could I do to prevent this from happening and so I don’t want to call jquery.js every time it is needed in an external file? I’ll leave an example below the flow of my application.

inserir a descrição da imagem aqui

To explain better:

The archive Index.php has the line below

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

and the detalhes.php for Jquery functions to work needs the same line above.

  • You’re probably using it $("element").click( ... ), if so, replace it with $("element_parent").on("click", "element", function() { ... })

  • No, I’m using $(Document). ready(Function(){}).

  • Add how you use AJAX in your question

  • Ajax is one of the cases, this occurs with other imports of js

  • @Rafa_dev and how you are assigning the events (from click, change etc) to the elements?

  • @Valdeirpsr this is one of the functions that I need to place the js call on all the pages that I use -> $(Document). ready(Function () { $("#product name"). typeahead({ source: Function (query, result) { $.ajax({ url: "helpers/z-aux_product.php", type: "POST", dataType: "json", date: {query: query}, Success: Function (date) { result($. map(data, Function (item) { Return item; }); } }); } }); });

  • Assume that an Ajax request should basically return an HTML (in your case, a JSON). jQuery is Javascript that should only run in the browser. If you are using jQuery in the PHP page requested by Ajax, it is an error, because the PHP page is not running in the browser, but on the server, that is, if you place the jQuery library in the requested PHP page, jQuery will have no effect there, it will just be returned to the page that called the Ajax.

  • summarizing, any Javascript code (such as jQuery) that you put in the requested PHP page, will be executed not there, but in the return of Ajax if you enter the Answer somewhere on the page that made the request.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.