pethel
pethel

Reputation: 5537

$.ajax get the request

Hi is there a way to get the request from a post so I can print it?

I would for example like to get this(logged in the server).

/App/user/[email protected]&dob=Fri Oct 05 2012 10:23:25 GMT+0200 (CEST)&childPortions=&tips=on&firstName=]

I know there are tools for this but that is not interesting to me right Now.

$.ajax({
    type: 'POST',
    url: "/App/user/",
    data: profile,
    cache: false,
    success: function(data){            
       $(".response-container").html(JSON.stringify(data, null, 2));
    }

});

This looks interesting (jQuery.param())

The data option can contain either a query string of the form key1=value1&key2=value2, or a map of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. This processing can be circumvented by setting processData to false. The processing might be undesirable if you wish to send an XML object to the server; in this case, change the contentType option from application/x-www-form-urlencoded to a more appropriate MIME type.

edit: The .ajaxSend never gets executed. The success function is called. How can this happend?

$(document).ajaxSend(function(e, jqXhr, options) {
    alert("hallo");
});
$.ajax({
    type: 'POST',
    url: "/App/user/",
    data: profile,
    cache: false,
    success: function(data){            
       console.log("ajax sent!")
    }

});

Upvotes: 0

Views: 101

Answers (3)

Jon
Jon

Reputation: 437336

You can use the .ajaxSend global event handler to process all AJAX request just before they are sent to the server. The parameters passed to the event handler provide all the information you will need.

Live example.

Upvotes: 1

markpsmith
markpsmith

Reputation: 4918

In C# you can use

Request.RawUrl

Upvotes: 0

wroniasty
wroniasty

Reputation: 8052

Of course there is a way to get the request data on the server-side. How - depends on what kind of backend you are using (PHP,JSP,ASP.NET,DJANGO....)

In PHP you can check $_SERVER['QUERY_STRING'] or $_POST.

Upvotes: 0

Related Questions