Multiple use of .post in jquery
Good day!
I am trying to use jquery .post(). My problem is I want to get data from 2 different Action (java-struts2). Instead of getting the data of test2, it results to resending the page twice... so the data in my JSP also doubles.
My code is as follows:
$(function(){
$.post("test", function开发者_C百科(data) {
$("#tester").html(data);
});
$.post("test2", function(data) {
$("#tester2").html(data);
});
});
HTML:
<div id="tester"></div>
<div id="tester2"></div>
How can i do the retrieving the data from 2 different actions(java) without the need of sending the data twice?
Thank you
When you send the JSON response from the server, group the data together something like this:
{
"tester": [foo, bar],
"tester2": "hello world"
}
In your $.post
callback, you will now have access to both piece of data in your data
var.
console.log(data.tester) //=> [foo, bar]
console.log(data.tester2) //=> hello world
精彩评论