1110
1110

Reputation: 6839

How to hide details in jquery ajax from browser page source

I am using jquery for all my ajax thing, I don't know if that is fine but I use that for now.
I have one text input when user type characters in it I call server side get some values and add them on the view.
Code that I use bellow works fine but I want to improve it a little.
How can I make this ajax call so that users that want to investigate my page source code can't see what I call here?
So basically I want to hide from page source what url, what type and data send I use here, is it possible?

$(function () {
        $("#txtSearch").keyup(function (evt) {        
            $.ajax({
                url: "/Prethors/Users/SearchUsers",
                type: "POST",
                data: "text=" + this.value,
                success: function (result) {
                    $("#searchResult").prepend("<p>" + result + "</p>");      
                }
            });
        });
    });

Upvotes: 5

Views: 23041

Answers (4)

abhilashv
abhilashv

Reputation: 1482

Use console.clear(); after you ajax calls :P It just clears the reqs from the console but you still cannot hide client side calls.

Upvotes: 1

Evan
Evan

Reputation: 6115

overall, you shouldn't worry about this. there is no way I'm aware of to hide your ajax calls, but you shouldn't need to.

-you could encrypt the info.

-you could use comet to stream the data on a persistent connection. (super complicated).

-follow good server security practices and not worry about it.

source: here

If you are really worried about this, you could set up kind of an anonymous URL, which will then redirect to where you really want to go based on some variable which is arbitrary.

for example, instead of going to "/Prethors/Users/SearchUsers"

go to "/AnonymousCall?code=5"

from which you could execute the code you want for searchusers

Upvotes: 4

Terry
Terry

Reputation: 14219

You can't hide client-side code. You can disguise it with minification but sensitive data should always be stored and processed on the server-side.

Upvotes: 3

Michael Dillon
Michael Dillon

Reputation: 1037

No, a user will always be able to figure out what calls you are making if you include it in javascript.

You can compress and minify the javascript, but a determined person will always be able to find your url calls.

Here's a js compression site, for example. http://jscompress.com/

Upvotes: 4

Related Questions