Malformed error in firefox

I have removed some data from the server that looks something like this: 1:some values@2: some other@3:some more

. I parse it in the client and it works well with chrome, but firefox seems to be throwing this error.

I even tried setting dataType to text, which didn't work either. I searched SO for similar questions and found it to be a match . But I am accessing it via http only as opposed to the problem in this thread.

EDIT:

    setInterval(function(){

            if($thisUser)
                $commonURL= "checkRequest.do?user="+$thisUser ;
            else
                $commonURL= "checkRequest.do?user=null";

            $.ajax({                            
            url:$commonURL,
            contentType: "text/plain",
            dataType: "text",   
            success:function(result){
                if(result[0]=="1")
                        window.location="playGame.do";
                else if(result[0]=="2"){ 

                    result1=result.substring(1,result.indexOf("@")); 
                    resultTemp="";
                    for(i=0;i<result1.split(",").length-1;i++)
                        resultTemp += "<a href='#' class='oppRequests' id='"+result1.split(",")[i]+"'>"+result1.split(",")[i]+"</a>, ";
                    $('td#oppRequests').html(resultTemp);
                    resultTemp="";
                    $("a.oppRequests").click(function(){
                        $thisUser = $(this).html();
                        $.ajax({

                        url:"postRequest.do?confirm="+$thisUser, 
                        success:function(result){

                    }});
                    });         

                }
            }
            });

},10000);

      

Pls help me with this :)

someone will answer this: p I have a correct way to achieve what I want, but I would like to know the problem.

0


source to share


2 answers


One can make sure that the solution to your problem and speeding up your script is that instead of parsing your own data format as text, you should use the inline JSON format. This is supported in jQuery by simply changing the 'datatype' parameter to 'json'. This will allow you to simply access your results from the server using the "result" var without having to do any string matches.

In essence, your returned JSON string should look something like this:

{ key1: 'some value', key2: 'some value'}

      



And you can access it with result [key1], result [key2] in your success function.

Generating the JSON backend is very easy, I'm not sure which language you are using, but many languages ​​have built in JSON encoding functionality.

+3


source


Solved the problem by changing the mimeType!



+1


source







All Articles