JQuery ajax call only from HTML page

Given the following jQuery code that calls the ajax call:

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});

The problem is that the user can manually enter test.html in the URL and see the response on the screen. How to avoid this?

+4
source share
3 answers

One way to do this is to create a variable in another script or location so that the user sees only the variable name.

Also send the request via the post method and make the ajax server response page respond only to the POST request (say, using some server-side language such as PHP, ASP.Net or JSP). Thus, even if the user finds out the path to the URL, he will not be able to view its contents.

+3

HTTP header. Ajax beforeSend. PHP .

+3

No, you can’t, AJAX calls are basically just HTTP calls and can be accessed directly.

0
source

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


All Articles