Hi,

how can I hide a url from jquery/ajax code for example:

function func123()
{	
	$(document).ready(function(){
		$.getJSON('[B]http://127.0.0.1/~nertos/file/my_web/file.php[/B]', function(res){
				......................					
		});	
	});
		
}

Thx 4 help;)

any ideas?:)

I don't think its possible. The client-side code must know the URL to which to send the request. You can assign the URL to a javascript variable, the variable could be loaded in another .js file, and then you can substitute that variable for the raw URL when calling the getJSON function.

The bottom line is that the jquery/ajax code needs to know the url to work as expected. If you are simply trying to hide it from "right click -> view source", try loading it into a variable in another .js file. If you are trying to hide it from users, then thats a lot harder. Anyone with a Firebug plugin for Firefox can trace all AJAX calls including the URLs they were sent to.

Even if you setup some kind of URL re-writing scheme, the user can still request the URL found in your page source and the server-side would not know the difference.

If you don't want people to browse to that location, why are you using it? What is at that location that you don't want people to access?

R

@robothy

I have only data in this location, but I want know, it is possible to hidden this link;)

Yes. To hide the link, use a token. If you don't want the link accessible, full stop, don't put it on your website!

If you want people to access the content, you have to link to the content... that is how the internet works...

Hidden value for what? For the URL itself? Or are you trying to hide the output of the page file.php if it is not requested from the javascript?

If latter is the case, here is something you can try.

1) Set a cookie with some known value (the return value of time() for example).
2) Pass that same value in your URL.
3) In the PHP code check the value passed in the query string with that set in the cookie and only if they match output the content.

Of course, this can also be bypassed fairly easy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.