1. #1
    Sencha User
    Join Date
    Jul 2012
    Location
    USA
    Posts
    29
    Answers
    2
    Vote Rating
    0
    jenis35@yahoo.co.in is on a distinguished road

      0  

    Default Answered: Uncaught Ext.Error: You're trying to decode an invalid JSON String:

    Answered: Uncaught Ext.Error: You're trying to decode an invalid JSON String:


    Hi Guys,


    I am getting following error which submitting my extjs form.


    ***Uncaught Ext.Error: You're trying to decode an invalid JSON String***


    Please find my code below. Below is my js file.

    Code:
        Ext.onReady(function() {
    
    
    			var simple = Ext.create('Ext.form.Panel', {
    						
    						frame : true,
    						title : 'Login Form',
    						bodyStyle : 'padding:5px 5px 0',
    						width : 350,
    						fieldDefaults : {
    							msgTarget : 'side',
    							labelWidth : 75
    						},
    						defaultType : 'textfield',
    						defaults : {
    							anchor : '100%'
    						},
    
    
    						items : [{
    									fieldLabel : 'User Name',
    									name : 'userName',
    									allowBlank : false,
    									emptyText : 'UserName'
    								}, {
    									fieldLabel : 'Password',
    									name : 'password',
    									allowBlank : false,
    									inputType : 'password',
    									emptyText : 'Password'
    								}],
    
    
    						buttons : [{
    							text : 'Save',
    							handler : function() {
    								var form = this.up('form').getForm();
    								form.submit({
    											url : saveFormUrl
    										//	waitMsg : 'Sending the info...',
    										//	success : function(fp, o) {
    										//		Ext.Msg.alert('Success',
    										//				'Form submitted.');
    										//	}
    										});
    							}
    						}, {
    							text : 'Cancel'
    						}]
    					});
    			simple.render(document.body);
    			simple.getEl().center();
    		});
    
    
    
    
    This is my controller class..
    
    
        @Controller
        public class UserController {
    
    
    	private static final Logger logger = LoggerFactory
    			.getLogger(TController.class);
    
    
    	private TService tService = null;
    
    
    	@Autowired
    	public void setTService(TService tService) {
    		this.tService = tService;
    	}
    
    
    	@RequestMapping(value = "/index.html", method = RequestMethod.GET)
    	public String home() {
    		System.out.println("Welcome home!");
    		return "login";
    	}
    	
    	@RequestMapping(value = "/save-form.html", method = RequestMethod.POST)
    	public ModelAndView submitData(User user){
    		System.out.println("User name:"+user.getUserName());
    		ModelAndView mv = new ModelAndView("htmlLinks");
    		return mv;
    	}
    
    
    
    
    This is my save-form.html file.. 
    
    
    
    
        <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
        <%@ page session="false"%>
        <c:set var="ctx" value="${pageContext.request.contextPath}" />
        <html>
        <head>
        <title>POC</title>
    
    
        </head>
        <body>
         Welcome User !!
        </body>
        </html>


    Could anyone tell me what am I doing wrong? and what should I do as a solution? I am using ExtJs 4 and Spring MVC.




    Thanks.
    Last edited by scottmartin; 24 Jul 2012 at 11:52 AM. Reason: Please format your code.

  2. Thanks a lot scott for reply. It worked after I made this change for the button.
    Code:
    buttons : [{
                  text : 'Save',
                  handler : function() {
                    // The getForm() method returns the
                     // Ext.form.Basic instance:
                      var form = this.up('form').getForm();
                       form.submit();
                                        }
                                    },


    Thanks.
    Jenis

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,010
    Answers
    667
    Vote Rating
    460
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Please format your code in the future.

    What does your return JSON look like? are you encoding/decoding?
    If you test you JSON at jsonlint.com, do you get a valid result?

    Scott.

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Location
    USA
    Posts
    29
    Answers
    2
    Vote Rating
    0
    jenis35@yahoo.co.in is on a distinguished road

      0  

    Default


    Hi ,

    I am not encoding/decoding json. I am just trying to submit the data from extjs page.

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,010
    Answers
    667
    Vote Rating
    460
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I am just trying to submit the data from extjs page.
    right .. but are you receiving this on the response after the submit?

    Scott.

  6. #5
    Sencha User
    Join Date
    Jul 2012
    Location
    USA
    Posts
    29
    Answers
    2
    Vote Rating
    0
    jenis35@yahoo.co.in is on a distinguished road

      0  

    Default


    I am using Spring MVC in application, so first I am loading the controller and then It goes to jsp page where I have included ext js files and my own js file. Once this login page is loaded, I am submitting the page to spring controller and redirect to another jsp page.

    J.M.

  7. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,010
    Answers
    667
    Vote Rating
    460
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    The point I am trying to make here is .. when do you receive the error in your code?
    What are you using to debug your code? Firebug/DevTools (chrome)

    Your error suggests you are trying to decode an return JSON string ..
    Do you get a response back from the server?
    What does your header look like when you submit?

    We have established that you are trying to subtmit data, but what is going on after in the code?

    Scott.

  8. #7
    Sencha User
    Join Date
    Jul 2012
    Location
    USA
    Posts
    29
    Answers
    2
    Vote Rating
    0
    jenis35@yahoo.co.in is on a distinguished road

      0  

    Default


    Thanks a lot scott for reply. It worked after I made this change for the button.
    Code:
    buttons : [{
                  text : 'Save',
                  handler : function() {
                    // The getForm() method returns the
                     // Ext.form.Basic instance:
                      var form = this.up('form').getForm();
                       form.submit();
                                        }
                                    },


    Thanks.
    Jenis

Thread Participants: 1

Tags for this Thread