Posting and retriving data from an api in javascript - javascript

I want to post to an API in javascript and after posting page should redirect to another page and get the data from another API, can anyone help with the code. I will be using an html form to post data into an api

The Submit button of the form should trigger a function that posts the data to an API. This is a clear video on how to work with data and APIs in javaScript: https://youtu.be/Kw5tC5nQMRY
This is how to call a function when the form is submitted: https://www.w3schools.com/jsref/event_onsubmit.asp
Then you would redirect the user to a new page, where you can have code that will get data from another API. https://www.w3schools.com/howto/howto_js_redirect_webpage.asp

Related

How can I scrape data from LinkedIn without using any api

If you view the source of any LinkedIn profile then you can see information in this form
&quotfirstName&quot&quotDanish&quot&quot
I don't know how to get this data
Here the first name is Danish
How can I get this record using jQuery or Javascript if I send GET request using jQuery on user links and get all the HTML, is it possible? or any solution for this problem
You shouldn't. You will be breaking their Terms. User their API.
https://www.linkedin.com/help/linkedin/answer/56347/prohibition-of-scraping-software?lang=en

Google reCaptcha when you don't control the POST URL

I have a form that submits to a POST action URL I don't have control over, which leaves server-side validation on that URL out of the question. I need to be able to pass a pen test with reCaptcha and am curious if the below scenario would work.
One idea I had was to do all the normal client-side reCaptcha validation using the callback response and then enabling the submit button via JS.
That button would preventDefault() to submit the form to a different PHP file (via ajax). That PHP file would perform proper server-side validation, then based on the response submit the form to the main post url on the success ajax response or not via the error response via JS.
I could also load the form without a POST URL then populate the URL in the DOM based on the success ajax response prior to JS submit.
Does anyone have any better ideas or other ways I can validate recaptcha server-side even if I don't have control over the main POST URL?
Or do you think that client-side only validation could pass a pen test?
Thanks in advance for any input.

Validate a Django Form with external POST action

I have a Django form, which sends the form data to an external source(to be more precise, it is a PayPal payment form). The user enters the price for the product, clicks on the button and the POST request is send to PayPal triggering the normal payment process.
Now I want to use OTP (like Google Authenticator) to validate each payment.
How should the validation be realized? I thought of several scenarios, but none of them is really satisfying:
Should I send the request first to my site, validate the OTP and then redirect the User to the PayPal site with the data via a POST request, coming with the request? Problem: POST requests are not meant to be redirected and I don't know, how to realize it in django.
Should I write JavaScript code, which sends an ajax request to my site, and "activates" the form on success? Problem: smarter users could just activate the form from the browser console, without sending the ajax request. Does anybody know some kind of activation trick in JavaScript, which is not "hackable"
I would be glad to hear some more solutions from you or some suggestions, how the solutions above could be realized without the problems mentioned.
EDIT - My Solution so far:
I have done a work around and split the form in two. The first form checks the OTP and sends the data to my internal django view. It also creates a model instance with an generated invoice, which can then be checked in the PayPal IPN routine. The second form is a PayPal payment form, which sends the POST request to PayPal. You can find the simplified code in the following Github-Gist:
https://gist.github.com/BloodyD/2cd15f38d0f666cf3a73
First method - normal redirection after POST:
I don't know why do You think that there shouldn't be any redirect after POST request? In django it happens all the time, without that each page refresh directly after adding something to database will trigger adding it one more time.
To redirect user into proper paypal page, you can just send HttpResponseRedirect instead of normal response when form is submitted with valid form data. If not, display some error messages.
2nd solution: using javascript.
You can send url to redirect to (paypal url) in AJAX response, so user won't be able to bypass this. Simply put some form submitted by AJAX, if it returns URL to redirect, just redirect user. If not, display error message.

Posting data on server using asp.net

I have name and email id fields and want to post data to server to another website (if fields are valid) using form tags but i already have one form tag with runat="server", using second form tag causes second form to not show on page. I have JavaScript code to post data to server on form post. I saw something using action on button click, but how do i post data on button click
P.S I don't want to use iFrame, popup.
To send POST data on a form submit, try to use a submit button like this:
<input type="submit" value="POST_DATA" name="POST_PARAMETER_NAME">
Replace POST_DATA with your data you want to submit and replace POST_PARAMETER_NAME with the parameter name you want to access the data on the server.
If you already have a form on the page that uses asp.net web forms to communicate with the server then you would probably need to make an ajax request if you want to post back different data. This is quite easy these days using jQuery. The link bellow shows you how you may do this and how to create a web forms page that would accept your post. This way your current form and page would not need to change which is what it sounds like you are after.
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Parse a Json response array from server in javascript without loading the page

I am working on a webapp. I have a webpage that sends some data to the server via form tag. The server returns a json array. I want to know how to parse that json array without loading
my page. The purpose is to keep my webpage as it is and load some values from json array to
some text fields below my form tag for further processing.
edit: I have tried some examples for reading from json array but how to prevent webpage realoading.
Please use Ajax for this. Ajax calls are done using Javascript as per your requirement. If you are using library like JQuery it is quite simple to use.
Link to JQuery - Get: http://api.jquery.com/jQuery.get/
One of the ideas to save you from changing anything in your existing code is handle onsubmit of the form. Send your get/post on submit via ajax and cancel the submit of the form.

Categories

Resources