Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Use JSON post with AJAX #56

Closed
pabloaotero opened this issue Jun 2, 2016 · 3 comments
Closed

Use JSON post with AJAX #56

pabloaotero opened this issue Jun 2, 2016 · 3 comments

Comments

@pabloaotero
Copy link

Hi,
I really like this project. I'd like to contribute in some way!

Is it possible to use AJAX (jquery or xmlthhpRequest) for JSON post? I couldn't make it work. Do yo have some example?

Which is the best way to use JSON examples through browser?

thanks a lot
Regards
Pablo

@eidheim
Copy link
Owner

eidheim commented Jun 2, 2016

Thank you, but I would suggest you read up on HTTP a bit. There should be no problems sending POST with json to this server, although you have to direct it to a defined resource (see http_examples.cpp).

@pabloaotero
Copy link
Author

Thanks for your response.
Yes, I'm trying with that example but I can not make it work with ajax. I always get an error.
I'm probably doing something wrong and I'll review it again.

Regards,
Pablo

@pabloaotero
Copy link
Author

pabloaotero commented Jun 2, 2016

Ok, it works.

var DTO = { "firstName":"John", "lastName":"Smith", "age":"25" };

var datain = JSON.stringify(DTO);

$.ajax({
async: true,
type: "POST",
url: "http://localhost:8080/json",
data: datain,
contentType: "application/json; charset=utf-8",
timeout: 3000,
processdata: true,
success: post_function_Ok,
error: post_function_Nok
});

The problem was I had added "dataType: 'json'" as expected data format from server.

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants