0

I am retrieving some data from the server which 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 throw this error.

I even tried setting the dataType to text which didnt work as well. I searched SO for similar questions and found this to be matching. But I am accessing it through http only unlike 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 out of this :)

somebody pls answer this :p I have got the proper way to achieve what i want yet I would like to know the problem.

Community
  • 1
  • 1
sarath
  • 498
  • 2
  • 12
  • 19

2 Answers2

3

One thing for sure that will solve your problem and speed up your script is if instead of parsing your own data format as text, you should use the built in 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 string in JSON format should look something like this:

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

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

Creating JSON server side is easy, I'm not sure what language you are using but a lot of languages have built in JSON encode functions.

Dunhamzzz
  • 14,682
  • 4
  • 50
  • 74
  • Thank you Dunhamzzz. I should be really stupid for not implementing this. I am new to ajax and haven't thought of using JSON so far. Anyway can you tell me the problem in my code? – sarath Mar 23 '11 at 14:01
1

Solved the problem by changing the mimeType!

sarath
  • 498
  • 2
  • 12
  • 19