HTML form post response on same page - html

I developed a very simple portlet for Liferay which contains a form to submit a couple of parameters to an external Webservice. My problem is that when I press submit I get redirected to the URL of that webservice.
Is there a way to suppress the redirection and show the webservice response in the same portlet that i made the call from?
Many thanks in advance for your feedback this is much appreciated.

You have to use javascript (AJAX) for send data to the webservice and directly get the response without redirecting the user. Then with the data you received from javascript, you can display them on the page.
You can do this with Jquery and the function ajax().
Hope, I've helped you :)

Related

Execute a function once HTML is rendered after web service call - AngularJS

I want to execute a piece of code once view is completely rendered.
Click on button, web service will be called
Once response is received, lot of data will get rendered on ng-repeat
After view is completely rendered, execute a piece of code
I know I can use callback once response is received but HTML rendering might take time. To avoid that I can also write my piece of code in $timeout function but that doesn't feel right approach to me. Any suggestions?
Thanks in advance!

HTML Form arguments to angular page

I have a static HTML page with a form on it asking for very basic information (Name, email).
This form will help pre-fill 2 fields of the registration process of my angular app.
the problem is that the URL that is being generated when submitting the form is
http://server/?name=xxx&email=xxx#yyy.com/#/account/create/infos
What my angular app is expecting is :
http://server/#/account/create/infos/?name=xxx&email=xxx#yyy.com
any idea how I can achieve that ?
thanks a lot
you can try setup your form to method post
<form method="post">...
Then in controller you get post-param and process it

submitting a form that doesn't has an action

I am trying to submit that form on the site from java. up till now i found the POST-DATA that is send using httpFox. but the problem that the form doesn't include an action that i could use. here is the link
http://tamarod.com/index.php?page=english
the data that is sent on submit is
Member_Name=&National_ID=&governerate_id=0&district_id=&Email=&Date_Of_Birth=&Submit=I+Accept
but i tried adding this line beside the url on the browser to try it but nothing happens..
I figured out the problem. I was missing SetDoInput() and SetDoOutput() in my HttpConnection. so i can POST and GET data.

Google Chrome show ajax response

I am using Google Chrome Developer Tools to try to see the response of some AJAX url's.
The problem is that when I click on the NETWORK TAB, then on the link, then on RESPONSE, I see this text : "THIS REQUEST HAS NO RESPONSE DATA AVAILABLE".
I have been using FIREBUG and I am 100% sure there is a response from that page.
Can somebody help with this ?
Thank you !
You can try manually checking if there's a response or not
So, generally when dealing with ajax, in most cases we use the POST, You can create a 'same structured' page to handle same input/response but using Get method and print the output data as normal.
This way you can see if there's any response/errors in your script very easily

How to submit data from an html page forcing the browser keeps the page unchanged

First let me set the situation.
I am writing a simple client html page and a simple server side program.
In detail, the page has a submit button to POST some data to the server program.
The problem is that any time I test the page to push the submit button ,the browser displays the new page which displays only the return message my server program returned.
How can I modify the html or the server side program so that the browser keeps the page unchanged before after the submit button is pushed.
I know an easiest way ; letting the sever program returns the same string as the client html page.
Thank you in advance.
In a regular form submission, your page will be whatever the server sends back. The form's action might be the same page, and then your server-side code can read the value of any input fields, and set the values in the response back to what they were in the request. This should result in the page looking the same as it did before the submit button was pressed. However, the page has "changed" in the sense that it was reloaded.
Alternatively, your form can make an Ajax request, which means that you'd need to use Javascript to intercept and stop the form submission, and then use additional coding to send the Ajax request, and then receive and process the response.
What you want is probably a postback:
http://en.wikipedia.org/wiki/Postback
1.) AJAX
You could use JavaScript and AJAX to POST the data.
2.) IFrame (not recommended)
You could also create a hidden IFrame and set the target attribute of the form to it.
What you want to do doesn't seem to be very clear.
If you want to submit your POST data without loading a new web page, you can use Ajax. It may be simple to do it in jQuery, and even simpler if you serialize your form data.
$('form').submit(function() {
$.post('your-post-url',$(this).serialize(),function(data) {
alert('Data posted!');
});
return false;
});