Hello all I wanted to pass the data from text box to REST api as POST method and receive and show JSON data .Kindly guide me how to frame the JQUERY to pass the data to a REST api URL
for HTML
<textarea rows="10" cols="50">This is a Sample text.Delete to type new </textarea>
<button>Process Data</button>
Javascript
(function ($) {
$('button').on('click', function () {
// remove resultset if this has already been run
$('.content ul').remove();
// add spinner to indicate something is happening
$('<i class="fa fa-refresh fa-spin"/>').appendTo('body');
Thanks can you please guide me with more code that will be needed to display the results fetched from web page on the website after the ajax POST method sends data to URL
You need to place the post request inside the button event listener (on click)
Also, you do not need to remove the UL, if you overwrite the innerHTML of it ($(element).html()) See example in codepen below.
How does the data look like? Will you get a JSON object or an array? What content is in there that you want to display as a list? Is it just an array of strings?
This is something you have to figure out. You could use postman to test your REST API. to see what the data looks like. If the content type of the response is JSON, it will be turned into a javascript consumable object for you. (the data parameter of the function)
I prepared a little codepen for you with a REST API I created a while ago with test data:
Pay close attention to the request in your dev tools. If you make a post or get request, observe it with the network tab (chrome or firefox) and switch to XHR: (the tab has to be loaded before the request is made)
There you can inspect the data you will receive. Alternatively, you can throw in a console.log statement in the function to see what the data looks like.
This is all described in the documentation for the Gate Cloud API. If you don’t want to do it yourself, you should pay someone to do it for you, since all public APIs are intended for the programmer to read its docs before using it.
They don’t have a great documentation for javascript use cases, as it looks like :\ it should be possible though. I can understand that this is tough to understand as newcomer.
That’s why I am in forum being a developer and love to handle things myself.But I am not clear how to pass the data in URL ,Like I guess the URL structure is https://…/endpoint?key=value&key=value so should I pass key ID as in my account api details and later password is mentioned,these are the queries I wanted to know as I am interested to do things by myself.Hope I am clear
$.ajax({
url: 'https://cloud-api.gate.ac.uk/process-document/generic-opinion-mining-english',
type: 'POST',
data: 'some test strings I want to compare that I would hate to be mined by your api.',
contentType: "text/plain"
}, function(data) {console.log(data)})
What you do with the data and how you display it, is the only thing left to do.
Thanks it is fine I wanted guidance on code to let the data from the text area to be passed to the REST API using post method like the code contains data :‘some test strings I want to compare that I would hate to be mined by your api.’,