Firefox - Replacing The Whole Page By The New One In Ajax Response

Sep 24, 2006

We have the following situation - when Ajax request is sent what's
being returned by the server is usually an XML (which is used for DOM
updates) but sometimes it's HTML which is a whole new page that should
replace an existing one. I.e when we issue an Ajax request we don't
know what will be returned and analyze the response to act accordingly.

Now, the way to replace the current document with a new one used to be
easy and portable for both browsers (we're only supporting IE6 and
Firefox 1.5):

document.open();
document.write( head );
document.write( body );
document.close();

where "head" and "body" are two parts of the result HTML. We had to cut
it to two (rather than going simply with document.write( NewHTML ))
because of IE - our head section contains references to external
JavaScript files (<script type="text/javascript"
src="sth.js"></script>) and IE only loads them when document.write()
call ends. So if body contains any script block (<script
type="text/javascript".. </script>) using any of JS referenced by
head - IE would fail with something like "Resource undefined" if we
push the whole new HTMl in one go by using document.write( NewHTML ).
But it worked perfectly fine in Firefox, meaning

document.open();
document.write( NewHTML );
document.close();

did the job just fine. What's even more important - it also evaluated
all JavaScripts correctly - both in external files referenced by the
head and in the JS blocks embedded in the body.

Until Firefox 1.5.0.6/7 where things stopped working completely - our
lovely and used-to-be portable code

document.open();
document.write( head );
document.write( body );
document.close();

caused Firefox to loose all CSS/JS and display an HTML only page (as if
CSS/JS were disabled). Removing document.close(); improved the
situation a bit by displaying the page with CSS this time but still -
*no* JavaScript was evaluated (meaning, JavaScript blocks embedded in
the document's body were not evaluated).

I took a different path from this point by pushing the new content to
document's head and body "innerHTML". It worked but not for JS
evaluation - I had to do that manually. To evaluate the JS referenced
in the head section of the document - I've traversed the head's DOM
tree while looking for the "script" nodes, then downloaded all of them
one by one using a synchronous Ajax calls (don't laugh!) and eval()-ed
the response. To evaluate JS blocks embedded in the body of the
document - I've traversed the body's DOM tree while looking for the
"script" nodes and eval()-ed them.

The problem is following: eval()-ing external JS files after
downloading them with Ajax doesn't work in 100% of cases - some
statements using Prototype functions fail to execute ("prototype.js" is
one of external JS files referenced in the head). Anyway, I'm almost
sure that what I'm doing is plain wrong, i.e it's sounds silly to
download all JS files referenced in the head and eval() them !

So how do I fix it ? Simply put - how do I replce the content of the
document to the completely new one received as a response to
asynchronous Ajax call ? The new content conatins doctype, head, body -
it's a completely new page. And all JS referenced in the head and
embedded in the body should be evaluated as well.

I really wish

document.open();
document.write( head );
document.write( body );
document.close();

was working in Firefox as before. Is it simply a Firefox bug, should I
submit it ? Btw, document.open.write.write.close() works just fine in IE6.

View 4 Replies


ADVERTISEMENT

Ajax/Prototype: OnComplete Fires Before Response Returned In Firefox

Feb 14, 2007

Simple ajax call seems to have some issues in Firefox. The "onComplete:" is
called BEFORE the response is returned by the call. Is there a coding issue
or a work around?

var ajax = new Ajax.Request( url, {method: 'post', parameters: params,
onComplete: evalInfo });

function evalInfo( request )
{
// do stuff with request
}

Should I have a timer that checks the request state before exec the
evalInfo?

View 4 Replies View Related

JQuery :: Ajax - Response Truncated - Limit To A Response Size

May 17, 2010

I have an ajax post which returns a large html response. It is getting truncated at 98784 characters everytime. Is there a limit to a response size or a way around this?

Using: IE7
jQuery 1.4.2
jQuery UI 1.8.1

Here is my ajax call:

View 1 Replies View Related

Ajax :: Replace Entire Html Page With Its Response?

Sep 20, 2010

I 'm having an ajax function that polls a server for a response. This response is in fact an html page which is dynamically constructed on the server. What I want is to be a able to replace my current html page ( not only the body ) with the html I am receiving as response from the server. I tried using document.write or innerHTML on html element but none of these does not seem to work. Here is a sample of the code I am using. code..

View 3 Replies View Related

JQuery :: Replace Current Html Page With Ajax Response?

Nov 1, 2010

I have page with an Ajax request which returns an entire <hml>..</html> page and I would like to use this response data to replace the current page. I wrote the following :

$.ajax({
type: "POST",
url: URL,
data: formData,

[Code]....

View 6 Replies View Related

Ajax: Server Response Correct - Viewed In Firebug - Page Not Updating

Feb 23, 2010

A couple of months ago I posted a question in these forums pertaining to some trouble I've been having with a webpage utilizing Javascript and PHP to implement AJAX.

Quote: I'm having two Ajax-related problems on a page I am working on at the moment. (Can't include the link since I'm a new Dev Shed member)

On this page, I have two buttons that use Ajax to fetch two separate forms and put them into a chosen div; that part works like a charm.

On said forms, there is a div that is meant to display any necessary error messages when the submit button is clicked. However, on the first time the page is visited and the form is chosen, the div won't display the error message. Only after refreshing the page/choosing the form a second time will the message show. I've been checking the response from the server via Firebug and the response is correct, it just seems like the page isn't updating correctly.

Secondly, once I refresh or choose the form again and the error message begins to show, if I enter values into the form fields and should be getting a different error message, it never updates. Once again, the server response is correct, but for some reason the page just isn't updating to reflect the new message.

I have been using the date field on the New Event form for testing; if you have Firebug, you should be able to see that I am getting the desired response from the server (look in the allErr div), but the HTML isn't changing with it. I have tried both using my own Ajax functions and using jQuery's Ajax implementation, but both give me the same problems. What am I doing wrong?

Code:

PHP Code:

View 4 Replies View Related

JQuery :: Evaluate Component Of AJAX Response After Injecting HTML Component In Page?

Nov 1, 2010

You have an AJAX request and the response is mixed HTML + JavaScript. The javascript is referring to elements in the HTML component. Currently the JavaScript gets evaluated first thing when success is triggered and the HTML is returned as a parameter. Obviously this is not going to work ( in this scenario anyway ). As a previous Mootools user I was used to Request.HTML's responseJavaScript parameter and evalScripts option. None of there options are available in the $.ajax implementation.

P.S. I know I could make the javascript a file and load it separately. I know I can make my response JSON and have the js and html in separate properties of the JSON object. I want neither.

View 4 Replies View Related

Xmlhttp Response In Firefox

Apr 3, 2006

There is a problem with XMLHttpRequest and Firefox when the
function that makes the asynchrounous request is called from another window. The URL
of the window does not change to the next page in which i am displaying
the response.

wat does getAllResponseHeader() function do?

View 2 Replies View Related

IE Vs. Firefox: Delay In Receiving Response From Servlet Using IFrame

Feb 6, 2007

when I use Firefox to run my application (this involves
sending an IFRAME request to the servlet and handling the response),
there is no delay in displaying the data after each response. But when
I use IE, there seems to be a 1-2 second delay. The script sends a
request using IFrame, goes through a loop to return script tags
containing data to the browser, and then data is displayed by the
browser and a new request is sent. For IE, when a new request is sent,
the delay in receiving the response is quite noticeable.

View 3 Replies View Related

JQuery :: .ajax And Page Refresh In Firefox - Can't Send Form Data In FF Without Page Refresh

Apr 15, 2010

So my problem is that i can't send form data in FF without page refresh (though in IE7-8 everything works smoothly).

My code fragments:

View 1 Replies View Related

JQuery :: AJAX Page Working In IE6,7,8 But Not In Firefox,Safari And Opera?

Oct 30, 2009

I am not a guru jquery coder and still have to learn alot, recently while learning jquery AJAX I have bumped into a weired issue, I have a apge right and in this page I have a dropdown list for people to select an RSS channel that they wish to know more about, the dropdownlist ahs an onChange event which when triggered it will get the value of the selected item in teh dropdownlist and post it to the other 'mini' pages that load on the same page via AJAX by using the GET method - ie: im passing the parameters like a normal querystring would. The problem is that when I assign the dropdown value to a variable called dropdown in the following line of code "var dropdown =document.getElementById('ddlChannelSelect');" it works in IE but not in the other browsers, I have debbugged this in FireBug and it seems that the variable dropdownlist is not actually getting the value of the actual dropdownlist nad it says 'null' or sometimes 'undefined'. Am I doing something wrong ? why is it that it is working in IE but not in other browsers ? can you pls give me a solution with some examples ?

[Code]...

View 4 Replies View Related

JQuery :: Replacing Input Elements Using Ajax?

Jul 29, 2011

Given input form elements on the display during page load, what is the proper way to replace the input elements when an Ajax call replaces the html? Here is a simple list of radio buttons:

[Code]...

I highlighted line 19 as that was the line I needed to add in order for the "shop" object to get the new input elements. Otherwise it was accumulating them. Can anybody explain the details of what was happening here and also confirm that the resolution is ? Is there a better way?

View 4 Replies View Related

JavaScript As AJAX Response (RPC)

Oct 15, 2006

Some servers return JavaScript as the response to an AJAX request. When
the response JavaScript is eval'ed it calls other JavaScript functions
already in the browser to update elements, etc. This seems like a good
system because it allows so much freedom in creating the desired
behavior in the browser. The required data doesn't have to be converted
to XML or JSON on the server. The browser doesn't have to have
templates for interpreting and converting this data into some change in
the browser. All of the conversion algorithms don't have to be written
and changed when new behavior is required. This remote procedure call
approach is the predominant system in the Ruby on Rails world.
(Unfortunately they are calling Prototype.js functions.)

However apparently some people seem to think this remote procedure call
approach is a bad idea. I can't see why it is so bad because it is so
lightweight and flexible. It also helps to keep the client less
intellegent which seems good in a world of incompatible client-side
bugs.

If I use some neutral data format like XML to accomdate different types
of clients then I have to write different client-side interpreters for
each type of client (browser, RSS, POP, cell phone, etc). Why not just
write different server-side code that generates the correct JavaScript
(or other) for the requesting client type?

When is the RPC approach such a bad idea?

View 5 Replies View Related

Ajax.response Max Size

Feb 24, 2007

I am using ajax / php where I am looking up some info from the
database and populating a select list dynamically, however I am
running into some sort of size limitation with the ajax.response
object. If the string I am passing to javascript from php is too large
javascript does not get it all the data. The magic number appears to
be 6123 characters, anything below that it works fine, anything above
and if I alert the ajax.response, I see the string is cutoff. Any
ideas where this limitation is defined?

View 11 Replies View Related

Ajax :: Wait Until Response Comes

Nov 15, 2008

I am using following code

Now what i want to do is: i have a callajax() function. with in this function i will call do_login() function. this do_login() handles an ajaxrequest and returns the responsetext.

Now i want to do some validation on this responsetext(in case of onsuccess). so i am trying to return value to callajax() function for onSuccess case in ajaxrequest.submit();

That is(onsuccess response) supposed to be some string( but not true or false). but i am always getting false in ajaxcall() function. i know the do_login() function is returning false before ajaxrequest completes

So i want to stop this and make do_login wait until ajaxrequest completes and then i want to return it's response to callajax() function.

View 3 Replies View Related

Using Eval() With Ajax Response

Apr 3, 2008

I am wondering how possible it is to use eval() to parse javascrpt that is pulled in through ajax(innerHTML)? I have found a few notes about this, such as:

Code:
var myObj = eval ( xmlhttp.responseText );

View 14 Replies View Related

AJAX :: Memory Leaks - Replacing Nodes With Frequent Updates

Aug 7, 2010

I've been searching the web for a while now, and I haven't come across a conclusive solution for memory leaks due to replacing nodes with frequent AJAX updates. I wrote a class that pulls an RSS feed frequently (e.g. every 5 seconds) and updates an HTML element with new information. In the process, it removes the old nodes and replaces them with new ones. It works fine visually. The only problem is that it has terrible memory leak complications; when I put the script on to run, it increases the memory usage by about 1MB every few seconds at an accelerated 1000-ms delay between updates!

(That's 100MB every few minutes!) I discovered this when I let the script run for a few hours straight, not thinking anything of it, and when I returned to my computer, it was frozen up Opera seems to be the worst at its memory management on this script, Safari and Chrome are in the middle, and Firefox seems to handle it the best, but nonetheless there are memory leaks in all four. (I haven't tested IE yet, but based on what I read, I would expect that it might even be worse than Opera!)

[Code]....

View 4 Replies View Related

Run JavaScript That Is Part Of AJAX Response

Apr 12, 2006

In my browser, I make an AJAX request. The server sends me a fragment
of an HTML document. That fragment has some JavaScript inside some
script tags. How do I run these scripts when the fragment arrives at
the browser?

View 12 Replies View Related

JQuery :: Ajax - Always Getting Empty Response?

Aug 27, 2010

I am making a call like -

$('#display').load(adnwurl, function(response, status, xhr) {
alert(response);
});

And also tried with -

$.get(adnwurl,
{},
function(data) {[code]...

In both the cases I am getting an empty response instead of expected html response.If I just copy paste this adnwurl in browser, I do get a proper html response. Its not working with ajax call.

adnwurl = "http [url]...site_id=4764&partner_id=70606a913077034c&timeout=5000&version=1.5&language=jsp&format=wap&testing=1&target_params=AGE=>29||DOB=>1981-08-[code]....

View 3 Replies View Related

JQuery :: Ajax Response And .html()?

Dec 22, 2010

I'm using $.ajax for an ajax request and I've setup a basic html form and if there are errors in the form when the user submits them my server side script is returning them in an array to the client with the errors.

If there are multiple values in the array, how do I display each error on its own line either using <li> tags or even just a <br/>? I'm injecting the ajax response into a div using .html() but how do I iterate the array within that div so I get one error message per line?

Do I need to construct the HTML on the client side after the ajax response has come back or should I do this on the server side before the data is even returned to the client? Right now I'm returning a raw array so that is why I'm asking the question about how to format things up and get the form errors into my div.

[Code]...

View 1 Replies View Related

JQuery :: AJAX Process The Response XML?

Aug 28, 2009

I'm truggling with this for a while now, without succes. Here is the

[Code]...

View 1 Replies View Related

JQuery :: Can't Get Attributes From Ajax Response?

Sep 7, 2009

I'm making a ajax call using $.ajax

[Code]...

View 2 Replies View Related

Ajax :: Redirect To URL Response Not Working

Feb 10, 2009

I have a simple ajax request that is supposed to (after a short timeout) redirect the page to the URL that the server sends back but it just wont work. It does work without the setTimeOut() function however.

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}

function go() {
var u = "http://site.com/";
http.open("GET", "go.php?" + "u=" + u, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
var redirURL = http.responseText;
setTimeout("window.location.href = redirURL;" , 2000);
} }
http.send(null);
}

View 2 Replies View Related

Ajax ::: Not Getting Response Text Some Times

Oct 6, 2010

i have wriiten a form in my php page and i did call an ajax function on onsubmit, based on my ajax response my form have to be submit...but i am not getting ajax response text some times. But some times i got it correctly..i have used post method in my ajax function.

formid="reserve";
var f = document.getElementById(formid);
var keyValue = "";
keyValue = buildKeyValueSearchFunction(f, keyValue);
alert(keyValue);
ajax_request = createRequestObject();
[Code]...

View 3 Replies View Related

Ajax :: Convert Response To Json?

Feb 15, 2011

I am using ajax to process a url. The result echoed back is

ok=true how can I convert that to json format so I can read that back in?

I can't edit how the response comes to me.

View 1 Replies View Related

AJAX :: XmlHTTPrequest - No Response From Server?

May 5, 2010

I am running the scripts below which should return a string containing a URL. So far, it cannot find the form contents in Firefox, but displays the non-dynamic data such as ?Location=. It won't work at all in IE.

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

[Code]....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved