Reputation: 1071
Given the following jQuery code that makes an ajax call:
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
The problem I have is that the user could manually enter test.html on the URL and see the response on the screen. How to avoid that?
Upvotes: 4
Views: 1068
Reputation: 308
One way you an do this to create a variable for in some other script or location so the user will only see the variable name.
Also send you request through post method and make you server ajax reponse page respond to POST request only( say using some server side language like PHP, ASP.Net or JSP). This way even if the user find out the path of the url it will not be able to view its contents.
Upvotes: 3
Reputation: 193
Try adding some kind of authorization in the HTTP header
. Use the Ajax beforeSend
setting. Then authenticate the header with PHP or any other server side language.
Upvotes: 3
Reputation: 2234
No you can't, AJAX calls are basically just HTTP calls and can be access with direct browsing.
Upvotes: 0