I am new to MVC and need a bit of help refactoring my code. In my view I have a http 'POST' request to a known URL that gets triggered when a user enters a new Client Name. The end point URL then returns three unique keys in json format that I then display on my UI. So I have four text boxes that display the following info:
Client Name: newclient
Key1: xyz
key2: 123foo
keys3: 456bar
My question is how do I make this request from the controller instead of everything taking place in the view ? I'm struggling to see how I can make the POST request from the controller when I need the information entered from the user in the view.
Thanks
Related
So I have a controller called 'HistoryController' which has a 'JsonResult' action which returns json data.
There is no associated View or Model with this method.
When I enter the url .../HistoryController/GetData, I get strange behaviour.
Instead of getting the json data (or maybe even an error message), I get the entire master page markup back in the browser. Why is this?
All I want is for some json data to show in browser but what I get is this:
I have an API Gateway that has a PUT method to update an item on a DynamoDB table. It is working fine if I use Postman and set the Content-type to application/json and include the JSON as the body. See below:
PUT: https://XXXXXXXXXX/dev/ID
Body:
{
"callerId": "XXXX",
"caseNumber": "YYYYY",
"count": 1,
"handled": true }
My main goal behind this is to be able to send a link to and end user where they can click and it automatically updates the Item in DynamoDB. Any ideas on how to create a link that makes a PUT request to and endpoint and passes JSON content that is going to be used to update the Item?
I have all the information I need I just don't know how to construct the link.
When a user clicks a link that you send them, their browser will always issue a GET request for that URL.
Why not also route GET requests for that resource to the same action as what you're currently doing with PUT?
I have a page html let's call it abc.html
There are AngularJS fields embedded in it.
I am now writing a GET and POST in scala which routes the fuzzy search arguments to the proper page on the server.
I am trying to understand the sequence in which things occur in order to implement a GET/POST requests (written in scala) which would happen when someone makes a search on the search bar on the abc.html page, and which would return elements from the database
Is it abc.html (search) --> http GET request --> backend ( AngularJS) --> Database?
In this case this would mean my http post or get request would pass in the html data model elements which would in turn hit the backend AngularJS controller page which in turn would hit the database, and the return ride would send the database results via an http request to the page?
Do I need to explicitly define my GET in terms of angular fields and the database model?
thanks
HTTP uses request-response pairs. This means you don't have to make another request to return anything to the client, you just need to write the proper response. Other than that, your idea is fundamentally right. The process would look something like this:
Type something into the search form on your HTML page
Submit the search form to your backend. This creates a GET or POST request depending on your form element's method attribute.
(At this point the browser is awaiting a response)
As the request reaches the server, your backend code can capture its data and make a query to your database.
(At this point the server is awaiting data from the database)
The database returns its results, your backend code is free to format it into a response to the client's original request.
The client receives the response and you can use your frontend code to display it to the user.
i'm developping a program in java ee.
i know how to display a view from a servlet with a code like this
this.getServletContext().getRequestDispatcher( VUE).forward( request, response );
where my view (VUE) is in a jsp page.
i know also how to return a json object with something like that
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonErreurEtRole);
I'm using google Gson to convert java objects.
Now i want to return a json object that contain a view in one field and some others messages in others field.
But i can't find how to do it.
Is there a way for that ?
EDIT
I will try to be more clear,
My problem is that : users ara requesting content by calling a servlet (a controller), i check their right on that content. And if they don't have right i send a message like "you don't have right ..."
that message should not replace any content in the html page but just appear as a notification.
So i wanted to return a json object like [message, content]
by the way i solved my problem by sending only message in a json object if user don't have right and html content if he has. And in je jquery code i'm testing the return type of the response.
I used this post :
jQuery ajax returned data: json and html mix?
I'm not sure how to ask this.
I have a HTML form that has several fields, including user id, which maps to a real name. I have jQuery validation of the form working.
Right now, I have to submit the POST request, to show the user's real name.
example: It should show "john doe" if the user types "3", before without clicking submit.
ID input: [3] ( john doe )
Do I use jQuery to retrieve this information? Do I also set up a new page, that has a response to a POST request, that returns 'john doe' as XML / JSON or something along those lines?
note: Using python's Flask. Maybe I should use Flask-Sijax ?
The Flask documentation has a good example using jquery to fetch a value from the server without posting the whole page.
If you wanted it to fire as a user types the number (rather then hitting a button in the example) you could use the .keyup event in jQuery instead of the .bind/click event shown the example.