Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2008

    JSONP woes w/S60 3.1 WebKit

    There is something extraordinarily weird happening with the WebKit browser when you try to JSONP (that is, dynamically create a script element for the purpose of executing a cross-domain server request). I am observing it on the two devices I have handy: N95 and E71-2. Short summary is this:

    - A page is loaded and body.onload() executes normally.
    - A JSONP request is initiated. NOTE: it does not matter whether the request is initiated from body.onload() call chain or elsewhere (onclick() event, timer event, anything).
    - The HTTP request successfully completes (per server log). Progress bar in the title updates as if the download has occurred.
    - Here's where it happens: the whole DOM is reset to post-loading condition: as if whole document was reloaded, but body.onload() were not fired.
    - However if you initiate the same JSONP request again at this point (let's say with an onclick() event), everything works perfectly.

    Below is a self-contained test case that accesses Yahoo JSONP service. You can use this URL to access the same page. Click on the big button to initiate JSONP. It fails the first time but works subsequently.

    The most frustrating thing about this issue is that I have one page (coded by me previously) where everything works consistently without as much as a hiccup. As far as I can tell, there is no substantial difference in the way JSONP is handled on that page from all the others I am struggling with.

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type='text/javascript'>
    function startJSONP()
    	var script = document.createElement( 'script' );
    	script.setAttribute( 'type', 'text/javascript' );
    	script.setAttribute( 'src', 'http://local.yahooapis.com/LocalSearchService/V2/localSearch?appid=YahooDemo&output=json&callback=onJSONP&query=jsonp' );
    	document.getElementsByTagName( 'head' )[0].appendChild( script );
    function stringize_id( id )
    	if( typeof id === 'string' && /[A-Z_$][A-Z_$0-9]*/i.test( id ) )
    		return id;
    	return stringize( id );
    function stringize( obj )
    	var result = '';
    	switch( typeof obj ) {
    		case 'object':
    			for( var i in obj ) {
    				if( result )	result += ', ';
    				if( obj.constructor == Array )	result += stringize( obj[i] );
    				else	result += stringize_id(i) + ': ' + stringize( obj[i] );
    			return obj.constructor == Array ? '[ ' + result + ' ]' : '{ ' + result + ' }';
    		case 'string':
    			return '"' + obj.replace( /["\\]/, function(c) { return '\\'+c; } ) + '"';
    		case 'number': case 'boolean' : case 'function' :
    			return obj.toString();
    		case 'undefined':
    			return '***Undefined***';
    function onJSONP( obj )
    	document.getElementById( 'msg' ).innerHTML = 'After JSONP';
    	document.getElementById( 'result' ).appendChild( document.createTextNode( stringize( obj ) ) );
    function onLoad()
    	document.getElementById( 'msg' ).innerHTML = 'After body.onload';
    <body onload='onLoad()'>
    <div id='msg'>Before script</div>
    <div id='result'></div>
    <input type='button' onclick='startJSONP()' value='Click HERE to start JSONP'>

  2. #2
    Registered User
    Join Date
    Oct 2008

    Re: JSONP woes w/S60 3.1 WebKit

    Oh, one more thing: the attached code seems to work properly for the very first time it comes up in the browser, or right after a cache reset. Do a page reload, and it breaks forever (until you reset cache again that is).

Similar Threads

  1. Replies: 3
    Last Post: 2008-08-12, 12:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts