[ 5 posts ]

Dirren Lang

  • Username: lexx
  • Joined: Tue Feb 02, 2010 8:10 am
  • Posts: 5
  • Offline
  • Profile

FF/Chrome throw MSG_ERROR instead of MSG_EMPTY

Post Posted: Mon Sep 20, 2010 6:30 am
+0-
Hi Everybody,

I have a quite strange behaviour while using yui2 DataTable.

The setup is quite easy:
Code:
   myDataTable = new YAHOO.widget.DataTable("ctd", myColumnDefs,
                myDataSource);


myDataSource looks like that:
Code:
myDataSource = new YAHOO.util.DataSource("some_php_file_with_some_get_params");
                myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;


Additionally I use AutoComplete to filter the ajax results.
Code:
 var getTerms = function(query) {
        if (myDataSource != undefined) {
            myDataSource.sendRequest('&query=' + query , myDataTable.onDataReturnInitializeTable, myDataTable);
        } else {
            // blahblah
        }
    };


If no results can be returned frome the php file called over ajax, it returns:
Quote:
{"ResultSet":{"totalResultsAvailable":0,"totalResultsReturned":0,"firstResultPosition":1,"ResultSetMapUrl":"","Result":[]}


My Problem:

In IE 6/7/8, if the quoted string is returend, YUI throws MSG_EMPTY, as expected.

But FF (2/3) and Chrome (5/6) throw MSG_ERROR.

Any Idea?

Best regards,
lexx

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: FF/Chrome throw MSG_ERROR instead of MSG_EMPTY

Post Posted: Mon Sep 20, 2010 6:49 am
+0-
Your quoted JSON has a missing curly bracket at the end but I guess that was an error in copying. The only strange thing in your description is the argument to your DataSource constructor "some_php_file_with_some_get_params" . You don't usually add your get parameters to the URL in the constructor. That is what the initialRequest configuration attribute is for, which goes into the fourth argument of your DataTable constructor, which is missing in your code.

The URL you use for the DataSource constructor is the base URL, that which remains the same all through the transaction. If you include your get parameters in the base URL, your extra arguments in the call to sendRequest will be appended to those, possibly confusing your server. A confused server often responds with a nicely formatted HTML error message instead of the expected JSON reply, and that causes the MSG_ERROR.

Another possible cause for error is not escaping the query. You should use:

myDataSource.sendRequest('&query=' + encodeURIComponent(query) , ...

otherwise, certain queries for example, with a whitespace, will truncate the URL or confuse the server with strange arguments.

Dirren Lang

  • Username: lexx
  • Joined: Tue Feb 02, 2010 8:10 am
  • Posts: 5
  • Offline
  • Profile
Tags:

Re: FF/Chrome throw MSG_ERROR instead of MSG_EMPTY

Post Posted: Tue Sep 21, 2010 4:40 am
+0-
Hi Satyam,

thanks for your answer.

I can exclude any server error since I see the XHR-Answer with Firebug/Chrome's DevTools.

Your're right,the end-bracket is missing in the quote. But as you suspected, it was a copy error, the server returns a correct json string.

I fixed the GET-Params and encoded the URI as you suggested.

Maybe you have any other idea..

thanks !

PS. This is my AutoComplete:
Code:
 var oACDS = new YAHOO.widget.DS_JSFunction(getTerms);
    oACDS.queryMatchContains = true;
    oAutoComp = new YAHOO.widget.AutoComplete(inputel, searchdiv, oACDS, {
        minQueryLength: 0
    });

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: FF/Chrome throw MSG_ERROR instead of MSG_EMPTY

Post Posted: Tue Sep 21, 2010 5:49 am
+0-
We haven't been doing things that way since 2.5.2. Autocomplete uses the same DataSource classes as DataTable does.

What versions are you using?

Dirren Lang

  • Username: lexx
  • Joined: Tue Feb 02, 2010 8:10 am
  • Posts: 5
  • Offline
  • Profile

Re: FF/Chrome throw MSG_ERROR instead of MSG_EMPTY

Post Posted: Thu Sep 23, 2010 7:21 am
+0-
Hi satyam,

a strange encoding setting of my apache caused some browsers to behave like that.


thanks - i solved the problem.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum