方法在我的jsp页面中不起作用

时间:2012-03-20 01:51:20

标签: jquery ajax post

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 lib。如果我的ajax方法语法错误,请建议我。

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'});

1 个答案:

答案 0 :(得分: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. 为参数提供您想要的内容,例如数据选项$.ajax中的“JSONFile”,请参阅我的回答代码
  2. 服务器示例request.getParams("JSONFile");//this is in java 中的
  3. getParameter 你的JSON上的

    尝试像这样改变

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