Perform $.ajax like POST request with paw-app - post

How Do I create a POST request with paw that is equal to a (jquery) ajax $.ajax({type: "POST", (...)});request?
I thought I could set the HTTP_X_REQUESTED_WITH to XMLHttpRequest but it does not work.
Whats the basic difference between an ajax/javascript POST and a regular POST from a form?

To simulate a POST request made via Ajax, what you need to do is to add an HTTP header:
X-Requested-With: XMLHttpRequest
Set the request method to POST
Enter the URL
Add the header mentioned above
Then enter the body in the Body tab, using the Form URL-Encoded mode:

When you are doing a post from a form, you are executing a submit event. In case you did not override the browser's default behavior for form submission at least for the case you are talking about, then the browser will execute it as an html post, which is a full postback. It sends the request and when the response arrives, it will be the new content of the page.
If you do a post with Javascript, then a request is sent and upon response, your callback will be executed, if existent.

Related

Create a URL with credentials

I would like to provide links to a website with the credentials already within the link. The link is:
https://mychart.covh.org/MyChart/
The credentials are:
Username = AllStarUser
Password = FiveStarPassword
I have tried
https://mychart.covh.org/MyChart/?Username=AllstarUser,Password=FiveStarPassword
and
http://mychart.covh.org/Mychart/logincheck.asp?login=AllStarUser&password=FiveStarPassword
but these don’t work. Any suggestions?
This is a POST form (method="post"). The form data has to be enclosed in the body of the HTTP request.
If it were a GET form (method="get"), you could enclose the form data in the URL, which is specified in the header of the HTTP request.
See also:
HTML 4.1: Form submission
HTML 5.2: Form submission
Stack Overflow: How are parameters sent in an HTTP POST request?
If this was a "get" -
https://mychart.covh.org/MyChart/logincheck.asp?Login=AllStarUser&Password=FiveStarPassword
would be correct.

Accessing request parameters in Orbeon form via POST

I want to access some request parameters in an Orbeon form sent via post to this form. I tried to use the XPath expression xxf:get-request-parameter('task_id') within the form, but this only works when the parameter is attached to the url (e.g. orbeon/fr/Activiti/dokumentfreigabe/new?task_id=4711).
Since I do not want to send all parameters in the url (but via POST and SSL), I need a solution to access request parameters in an orbeon form sent as a POST-Parameter.
You can't access parameters sent to the form with a form POST with an XPath function. Could you use an HTTP header to pass this value, instead of a form POST? If it possible, then you could use xxf:get-request-header('your-header').
If the form POST is done by the browser, and not by another server-side app or filter or reverse proxy, then you obviously wouldn't be able to set the header directly from the browser. However, you could continue doing the form POST from the browser, and add a servlet filter that extracts the value, and sets the value of a header, so you can then read it with xxf:get-request-header('your-header').

Symfony clear Post data

I need to clear the POST data ($request->getPostParameter()) so that if the user refreshes the page the data does not get resubmitted. How do I do this in symfony?
The general rule in symfony is to redirect (not forward) in a controller that accepts post data, and presumably writes to the database. You can this behaviour in the generated action.class.php when using generate-module
I needed to reload previously loaded page without redirect, because the request was sent by ajax... so I processed the form and then just changed method from POST to GET, which prevent form resubmittion, and then forwarded request to another controller. Here is the code:
$request = $this->get('request');
$request->setMethod('GET');
$response = $this->forward($controller, $params);
return $response;

rails ajax redirect

Here is my use case
I have a search model with two actions search_set and search_show.
1 - A user loads the home page which contains a search_form, rendered
via a partial (search_form).
2 - User does a search, and the request goes to search_set, the search
is saved and a redirect happens to search_show page which again
renders the search_form with the saved search preferences. This search
form is different than the one if step1, because it's a remote form
being submitted to the same action (search set)
3 - Now the user does another search, and the search form is submitted
via ajax to the search_set action. The search is saved and executed
and now I need to present the result via rjs templates (corresponding
to search_show). I am told that if the request is xhr then I can't
redirect to the search_show action? Is that right? If yes, how do I
handle this?
Here is my controller class
http://pastie.org/993460
Thanks
That's right. Either make the request non-XHR and redirect as normal, or you could try rendering the URL you want to redirect to as text or part of a JSON object which your AJAX request then uses to call document.location.href = [whatever] (but this seems hacky).
Right now what's happening is your XHR request is returning the result of the redirect, and not actually redirecting the page that made the XHR request.

Posting a form from Rails programmatically

How would I go about creating and posting a form POST request from inside some Rails code?
The use case I have is that I have received a form request, and I would like to forward this request on to a third party with my parameters intact.
I should add that I want to redirect the user out to the third party with the form too.
From ruby docs for Net::HTTP:
res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
{'q'=>'ruby', 'max'=>'50'})
You could just pass params as the second arg, eg:
Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'), params)
redirect_to some_path
Also, don't forget to require the lib:
require 'net/http'
require 'uri'
You're going to have to do this via Javascript, as there is no way of redirecting a POST request (as per the HTTP/1.1 protocol).
You might be able to do it this way:
receive the post form the user
change whatever data you mean to
respond to the request with a form full of hidden fields
automatically post that form to the third party via javascript on dom-loaded
Alternatively:
set the form action to be the third party url
intercept the onsubmit event with js
change whatever data you need, either by simple client-side manipulation of the form
or, post an ajax request to your app to treat the data, and replace the fields you need with from the ajax response
with the data now massaged, let the form go through to the third party

Resources