Skip to content
Advertisement

post html form results to api as json

I want to submit a form and have the values sent to the api in json format and save the response in a variable. When i try this using the below code i get an ‘Internal Server Error’ message.

JavaScript

The parameters the api takes are ‘season’, ‘num_teachers’, ‘num_students’. Once it has all the parameters it will send a result response back. How can i send my form results to the api and get back the response?

Advertisement

Answer

I don’t know why you using a jQuery plugin to send form in Ajax, totally useless.

JavaScript

Replace your function by that one. Remove action attribute on your html form tag. Now you handle errors and response from server. That means if the server returns an error, it will be displayed in your console and you will be able to know the problem. Other thing, do you really need this old version of jQuery, cause now we are at version 3.3.1.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement