问题描述:

I'm developing a web page using the hidden frame technique to retrieve some data from the server.

The data is updated in real time, and the server notifies the browser on each modification..

The component is working in both IE and Firefox, but in chrome, the callback function retrieved by the server is not executed in the client browser.

However i can see the connection opened in the developer tools, and the received data through that connection growing.

I have read that some browsers could have problems parsing and executing the data received from the server, but I wasn't able to find a solution for those cases.

Maybe i need to send some http header to this case, but i dont even know what to search.

EDIT: Code sample

This is the function i'm using to connect to the server. It is called after a sign in step. The sign in is implemented in the same way as the connect step.

function __sendConnectRequest()

{

document.getElementById(UID).setAttribute('value', __username);

document.getElementById(SID).setAttribute('value', __sessionKey);

document.getElementById(PID).setAttribute('value', __privateKey);

try

{

document.getElementById('connectFormId').submit();

}

catch (err)

{

alert("error connecting");

console.log("__sendConnectRequest: " + err.message);

}

}

var __connectResponseCallback = null;

function __setConnectResponseCallback(callback)

{

__connectResponseCallback = callback;

}

function __connectResponseHandler(statusCode)

{

if(__connectResponseCallback)

{

__connectResponseCallback(statusCode);

}

}

This is how i create my DOM elements. This elements are being appended to the body of the document, and the form has some input strings.

function getNewIframe(name, id)

{

//KNOWN BUG IN IE while creating iframes

//http://webbugtrack.blogspot.com/2007/10/bug-235-createelement-is-broken-in-ie.html

var iframe;

try

{

iframe = document.createElement('<iframe name="' + name + '">');

}

catch (ex)

{

iframe = document.createElement('iframe');

iframe.name = name;

}

iframe.id = id;

iframe.style.display = 'none';

return iframe;

}

function getNewForm(name, id, target, action)

{

var form = document.createElement("form");

form.name = name;

form.id = id;

form.method = 'post';

form.target = target;

form.action = serverUrl+action;

form.style.display = 'none';

return form;

}

网友答案:

The solution was solved by adding the multipart/x-mixed-replace header in the server response. This way, the data is executed in chunks and the browser doesn't need to wait for all the response to be received.

It seems it is an old standard in comet techniques.

相关阅读:
Top