我懷疑如何將json數據拆分爲字符串。我的意圖是iam動態創建幾個文本框並使用ajax發佈它們,以避免完整回發,這裏檢查我的ajax部分如何將json數據拆分爲字符串
function profileAndSectin_Submit() {
//alert('test123');
document.getElementById("hiddenSection").value = i;
$('#profile_form').submit(
function() {
alert(i);
var profileName = $('#profileName').val();
var Section1 = $('#Section1').val();
var dynamicData = " ";
for (var m = 2; m <= i; m++) {
var textbx = $('#Section' + m).val();//"Section"+m;
var dt="section"+m+":"+textbx;
//var txtbxval = document.getElementsByName(textbx).value;
var x = textbx ;
if (m <= m - 1) {
x + " ";
}
dynamicData = dynamicData +dt+",";
//dynamicData = dynamicData +":"+dt+",";
}
alert(dynamicData);
var Data = "profileName :"+profileName+","+"Section1 :"+Section1+"," + dynamicData;
alert(Data);
$.ajax({
type : "post",
url : "addProfile",
//data : {
//"profileName" : profileName,
//"Section1" : Section1,
//},
data :{"Count" : i,"Data" :Data},
success : function(msg) {
alert(i);
$('#divContent').load('addfields.jsp');
},
Error : function(msg) {
debugger;
}
});
return false;
});
};
和IAM發送這些值以一個控制器,主要的問題涉及到圖象在這裏,我怎樣才能retrive這些數據,如果IAM使用@RequestParam("Data")
字符串數據然後的IAM獲取的總數據作爲單個字符串,象
{ProfileName:profileName,Section1:section1,Section2:section2...}
但我想eac h字符串像profileName,Section2和Section3就像我想要的。
Controller.java
@Controller
public class SettingController implements HibernateConfig {
@RequestMapping(value = "/addProfile", method = RequestMethod.POST)
//public String home(HttpServletRequest request,@RequestParam("Count") int i,@RequestParam("profileName") String pname,@RequestParam("Section1") String Section1,Locale locale, Model model) throws IOException
public String home(HttpServletRequest request,@RequestParam("Count") int i,@RequestParam("Data") String data,Locale locale, Model model) throws IOException
{
System.out.println(i);
System.out.println(data);
}
所以任何想法的傢伙?
,我應該使用data.split(「」),在控制器或JS在你的控制器 – srikanth 2012-08-01 09:20:57
@srikanth(我已經更新了我的答案現在)。 'split(...)'是一個java'String'類方法。 – jelies 2012-08-01 09:36:04
@srikanth最終爲你做了這項工作嗎? – jelies 2012-08-14 06:53:46