2012-03-20 57 views
0
var values= {Title :title , BannerImg : bannerimgsrc ,Banneralt :bodyimgalt ,nbLink : navBarEditorLinks ,LinksEditor : links, Address : addresses}; 



var editorTXT =JSON.stringify(values);----This is my json String which i get when i submit my html form.I am extracting all the values from the form on submission. 
      alert(editorTXT); 

一旦我得到这个json对象,我试图发布到服务器使用.post或.ajax点击保存按钮。但是当我点击保存时,这个方法完全被忽略了。请告诉我如何使它工作。我正在使用jquery 1.6.2.js库。如果我的ajax方法语法错误,请告诉我。方法不工作在我的jsp页面

jQuery.ajax({type:"POST", url : " mailMgtCntrlS/init", 
data : { filename: filename, 
    cmd: cmd, 
    token: token,         
partitionid: partitionid         content_desc: content_desc,         EditorDefault: editorTXT},        
success :function(){         alert('successful');          var response = result.split(":");          document.saveNewsletterForm.token.value = result[1]; 
     },         dataType:'json'}); 

回答

2
jQuery.ajax({ 
type:"POST", 
url : " mailMgtCntrlS/init", 
dataType:'json', 
data :"JSONFile=" + { filename: filename, cmd: cmd, token: token, partitionid: partitionid content_desc: content_desc, EditorDefault: editorTXT}, 
success :function(result,msg){ 
    alert(msg); 
    alert(result.filename); // if you respose same with your post 
    //var response = result.split(":"); 
    //document.saveNewsletterForm.token.value = result[1]; 
} 
}); 

我建议

  1. 给予参数是什么,你想要的,例如 “JSONFile” 数据选项$.ajax看到我的答案代码
  2. 的getParameter在服务器例如request.getParams("JSONFile");//this is in java

对你的JSON试图改变这样的

{ 
    "filename": "filename", 
    "cmd": "cmd", 
    "token": "token", 
    "partitionid": "partitionid", 
    "content_desc": "content_desc", 
    "EditorDefault": "editorTXT" 
}