Using a variable in jquery load () doesn't work

this ultimately disappoints because it works on the development site, but after it moves to the site in real time, it stops working .: S

$('.menu_btn').click(function(e) {
//rel is used to tell me what html page to load
var url = $(this).attr('rel');
//load the new page into the div
$('#ajax_wrapper').load(url);
});

even more annoying when I hard code the url value in:

var url = 'http://www.example.com/pages/home.html'

It works without problems.

adding alert(url)gives the correct address of the address.

+3
source share
1 answer

Is the domain in the url the same as the domain of the page? If not, the problem you are facing is that

Due to browser security restrictions, most Ajax requests are subject to the same origin policy ; The request cannot retrieve data from another domain, subdomain, or protocol.

via jQuery docs

+3
source

Source: https://habr.com/ru/post/1784482/


All Articles