Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the url from which the ajax call has been made in the ajax function

Tags:

jquery

ajax

php

For example, I have an ajax request from the page http://www.abc.com/xyz/1 to the function controlling ajax.

Is there any way except sending it through the parameters so that I could know that in the function I can fetch http://www.abc.com/xyz/1 and realise that the ajax request came from here?

like image 818
Shivang Avatar asked Sep 05 '12 18:09

Shivang


People also ask

What is URL in Ajax call?

The url parameter is a string containing the URL you want to reach with the Ajax call, while settings is an object literal containing the configuration for the Ajax request. In its first form, this function performs an Ajax request using the url parameter and the options specified in settings .

How do you check Ajax URL is working or not?

$. ajax({ type: 'POST', url: 'page. php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' });

How get data from Ajax call in jQuery?

ajax({ type: "POST", url: 'test. php', data: {"type":"check"}, success: function(response){ alert(response); } }); There can obviously be more key-val pairs in data. In this case your alert should read: "The type you posted is check".


1 Answers

If the server wants to know from which page, or the server's location, then you can use this in the end, if PHP:

die($_SERVER["HTTP_HOST"] . $_SERVER["HTTP_REFERER"]);
like image 108
Praveen Kumar Purushothaman Avatar answered Oct 06 '22 00:10

Praveen Kumar Purushothaman