SRy SRy - 5 months ago 9
jQuery Question

Method is not working in my jsp page

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


Once I get this json object I am trying to post to server using .post or .ajax on click of save button. But when I click on save this method is completely ignored. Please suggest me how to make it work. I am using jquery 1.6.2.js lib. Please suggest me if my ajax method syntax is wrong.

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

Answer
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]; 
 }
});

i'm suggesting

  1. give parameter what do you want, example "JSONFile" in data option $.ajax see my answer code
  2. getParameter in server example request.getParams("JSONFile");//this is in java

on your JSON try to change like this

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