I am trying to send JSON data to server (https://exampleurl.com/example?data=) by setting the content of the data variable to valid JSON with the following properties name , email , urls.
Asked
Active
Viewed 462 times
-2
-
if you pass data in URL, then I guess you pass parameters in URL and you can get the data and convert them to JSON format. – Maytham Fahmi Jul 16 '15 at 22:31
-
can you send example of valid JSON format ? as i already tried but not getting 200 response. – Data Velocity Jul 16 '15 at 22:34
-
see this example of parameter to json converter in JAVA http://stackoverflow.com/questions/29381446/how-to-convert-url-parameteres-to-json-format/29388163#29388163 and get some inspiration. you can find tons of info on how to format JSON – Maytham Fahmi Jul 16 '15 at 22:36
-
2More practical way is to send JSON data via POST (ajax) – Maytham Fahmi Jul 16 '15 at 22:40
-
Hi, have you tried JSON.stringify(json)? – KN_ Jul 16 '15 at 22:42
-
I tried with this function but not getting 200 response – Data Velocity Jul 16 '15 at 22:46
-
@KN_ most I think most easiest way is send JSON data via Ajax post but not getting 200 response. – Data Velocity Jul 16 '15 at 22:49
-
why i am getting this error message while sending request via Ajax ? No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 500. – Data Velocity Jul 16 '15 at 23:37
-
@DataVelocity you need to allow CORS http://enable-cors.org/server.html – tenderloin Jul 17 '15 at 00:47
1 Answers
0
You cannot send JSON
data in url. You need to pass the JSON
data in the request body.
If using jQuery, use the following code:
$.post( "test.php", { name: "John", time: "2pm" } );

Ajay Kumar
- 1,154
- 2
- 10
- 24