Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I post JSON without using AJAX?

I have some data, lets say:

var dat = JSON.stringify(frm.serializeArray())

I want to submit this to the server using a roundtrip (aka, non ajax).

I know this is possible, but I can't find any literature on it. Ideas?

(I am using jQuery, if that makes it easier)

EDIT: while all of these answers so far answer the question, I should have included that I want an "content type" of "application/json"

like image 330
Aaron Scruggs Avatar asked Dec 13 '10 14:12

Aaron Scruggs


People also ask

Can you send JSON in POST?

POST requestsIn Postman, change the method next to the URL to 'POST', and under the 'Body' tab choose the 'raw' radio button and then 'JSON (application/json)' from the drop down. You can now type in the JSON you want to send along with the POST request. If this is successful, you should see the new data in your 'db.

What is difference between JSON and AJAX?

JSON (JavaScript Object Notation) and AJAX (Asynchronous JavaScript and XML) are two completely different concepts, one is used as a storage medium for data (JSON) while the other is used to retrieve data from a HTTP or FTP web server (AJAX) which is not dependent on the format of the data to be transferred, it can be ...

How do I POST JSON data using JavaScript?

How do I post JSON data using JavaScript? To post data in JSON format using JavaScript/jQuery, you need to stringify your JavaScript object using the JSON. stringify() method and provide a Content-Type: application/json header with your request.

Is JSON used with AJAX?

Many developers use JSON to pass AJAX updates between the client and the server. Websites updating live sports scores can be considered as an example of AJAX.


1 Answers

  1. Create an HTML form with unique "id" attribute. You can hide it using CSS "display:none". Also fill the action and method attributes.
  2. Add a text or hidden input field to the form. make sure you give it a meaningful "name" attribute. That's the name that the server would get the data within.
  3. Using JQuery (or plain old javascript) copy the variable "dat" into the input field
  4. Submit the form using script
like image 130
2 revs, 2 users 86% Avatar answered Sep 22 '22 18:09

2 revs, 2 users 86%