javascript - xml parsing error syntax error line number 1 column 1 in jquery ajax - Stack Overflow

Following is the code I use for an ajax call. While executing this it gives me an error xml parsing err

Following is the code I use for an ajax call. While executing this it gives me an error xml parsing error syntax error line number 1 column 1 in fiebug. I viewed some questions stating the same problem and they suggested that there was some syntactical problem. I checked again but couldn't find out the real culprit. Please tell me what I am doing wrong.

  $.ajax({type: "GET",
            cache: false,
            url: 'url',
            data : 'param1='+ param1val+ '&param2='+param1val,
            dataType: 'json',
            success: function(Obj){
                if(Some Condition){
                   //Some Code
                }else{
                  //else code
                }
            },
   
        });

Here goes some controller code.

   @RequestMapping(value = "url", method = RequestMethod.GET)
    public @ResponseBody SomeObject url(@RequestParam(value="param1val") String  abc ,@RequestParam(value="param2val") String xyz) 
   { //some code}

Edit I added some debugging code to JS and the controller code as well. To my surprise, control executes successful first es (in JS) and then goes into controller. Is it supposed to happen like this?

Following is the code I use for an ajax call. While executing this it gives me an error xml parsing error syntax error line number 1 column 1 in fiebug. I viewed some questions stating the same problem and they suggested that there was some syntactical problem. I checked again but couldn't find out the real culprit. Please tell me what I am doing wrong.

  $.ajax({type: "GET",
            cache: false,
            url: 'url',
            data : 'param1='+ param1val+ '&param2='+param1val,
            dataType: 'json',
            success: function(Obj){
                if(Some Condition){
                   //Some Code
                }else{
                  //else code
                }
            },
   
        });

Here goes some controller code.

   @RequestMapping(value = "url", method = RequestMethod.GET)
    public @ResponseBody SomeObject url(@RequestParam(value="param1val") String  abc ,@RequestParam(value="param2val") String xyz) 
   { //some code}

Edit I added some debugging code to JS and the controller code as well. To my surprise, control executes successful first es (in JS) and then goes into controller. Is it supposed to happen like this?

Share Improve this question edited Oct 28, 2020 at 6:41 supernova 2,1373 gold badges20 silver badges36 bronze badges asked Sep 23, 2012 at 11:44 sandysandy 1,1657 gold badges21 silver badges40 bronze badges 5
  • You should URL encode the req params in your javascript. See stackoverflow./questions/332872/… & xkr.us/articles/javascript/encode-pare – Zak Commented Sep 23, 2012 at 12:58
  • Reading the link,gives me impression that encodeURI is use in js.I am using jquery ajax,do I need to do that? – sandy Commented Sep 23, 2012 at 13:25
  • 1 Are you sure you don't getting json instead of xml? Could you post an example of your data, which produces the error? – Stan Commented Sep 23, 2012 at 17:45
  • From controller I do return a custom object.Shouldn't I use json than.Though I've tried with datatype=xml as well.It was no help either.:( – sandy Commented Sep 23, 2012 at 17:59
  • 1 What format is used for the object, and what format is set in http-header? Anyway, without an exapmle of data which produces the error, it will be just hit-and-miss guessing. – Stan Commented Sep 23, 2012 at 18:19
Add a ment  | 

1 Answer 1

Reset to default 1

Firefox shows this error if the response type is not set correctly. It tries to parse the response as XML. To fix it, set the response type for what you are sending back to the client, for example for JSON with Spring:

@RequestMapping(value = "url", 
                method = RequestMethod.GET, 
                produces = "application/json")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745674073a4639577.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信