I am studing the Spring MVC showwcase dowloadable from the STS dashboard.
Now I am studing how Spring MVC mapping the resources and I have some problem to understand the following thing:
So, I have the following link that generate an HTTP Request towards the "/mapping/produces" folder:
As you can see this link have class named "writeJsonLink" and for this class there is defined the following JQuery function triggered on the click of the link:
Ok, I have commented the code to try to understand its behavior (I am a beginner of Javascript and JQuery) and seems me that the behavior of this script is the following one: When I click the link, start the function that before send the ajax call to the web application check if the url of the clicked link is an address that end with .json extension.
In this case this case my URL don't end with .json (because my url is towards the FOLDER: /mapping/produces and not towards a .json file), so the function don't add the header "Accept", "application/json" to the HTTP Request body field.
Ok, now my problem is to understand what do this piece of code:
In succes case call a function having a parameter named json that simply call a method named showSuccessResponse passing to it the json obkect converted to String and the link.
Now, I know what showSuccessResponse do (I use it to create a span tag that show a message in my page next to the clicked link).
the problem is: who is the json parameter that I pass to the function in the success case. I am converting to String this parameter but: when and where I have created id?
If I execute my example when I click on the link appear me (next to the link) the following message: {"foo":"bar","fruit":"apple"}
Seems ad it was created an JSON object having the following key\value contents:
foo: bar
fruit: apple
But where is it created ?!?! boooo
When I click on the link and the method is executed I have the following message in my stacktrace:
So JQuery created it from the response it received from the server
"towards the FOLDER: /mapping/produces and not towards a .json file"
To help clear something up here. It is not a folder or a file. It is a URL. a routing path in a URL meaning the url contains the server/domain address, then the app name, then the path. If .json is ther eit is not to point to a file that ends in .json it is still just part of the URL path. It is not directories and files.
So when JQuery has its ajax method, it takes some callback functions. And it knows how to create the parameter and pass it to that callback function.
Mark Spritzler wrote:So JQuery created it from the response it received from the server
"towards the FOLDER: /mapping/produces and not towards a .json file"
To help clear something up here. It is not a folder or a file. It is a URL. a routing path in a URL meaning the url contains the server/domain address, then the app name, then the path. If .json is ther eit is not to point to a file that ends in .json it is still just part of the URL path. It is not directories and files.
So when JQuery has its ajax method, it takes some callback functions. And it knows how to create the parameter and pass it to that callback function.
Mark
Mmm I think that now is more clear for me but it still remains quite obscure for me...I try to tell you what I understood and what I'm missing in your reasoning (Please, have patience with a newbye)