/    Sign up×
Community /Pin to ProfileBookmark

Regarding Javascript

Hai All,

I need a small help regarding javascript.Actually I implemented code in Ajax with javascript and It is working fine.But I am getting output very late because of following statement.It takes nearly 3 mints to display result.But I need output within 30 secs .Please help me to resolve these problems

Problem:
script on this page mab be busy,or it may have stopped responding.You can stop the script now,or you can continue to see if the script will complete.

govind

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 01.2007 — If it takes 3 minutes to display, that means it takes 3 minutes to display. You might, probably decrease a little bit the AJAX response, but it depends on the code, which you have not posted. Anyway, I doubt you cand reduce it too much.

You should re-think the whole project. It looks like you want to request a large amount of data and to display it on page. There is nothing much you can do about, as javascript (as the main component of the AJAX) is a slow language.

Have you considered a server-side solution instead?
Copy linkTweet thisAlerts:
@nanna_govindauthorOct 01.2007 — Thank u Kor,

For your valuable reply.In the javascript we have passed 3 url as requests to remote server and getting source code.We are parsing those source codes and getting the desired values/string/url.Actually we are doing that process.Now you can have some idea about what we are doing and why the response is getting delay.Please help us.
Copy linkTweet thisAlerts:
@KorOct 01.2007 — You provided us too less information to be able to see [I]why[/I] the response gets a delay, [I]if[/I] the response gets a delay or even if there [I]is[/I] a delay.

Now, AJAX works like that. It sends a request (very much alike a classical submit) to a server-side application (let's call it SSA). That SSA, on its turn, sends a request (based on data received from AJAX object) to a Data Base. SSA received the answer from DB and pass it back to the AJAX object. Now javascript "decompiles" that answer and display it on the page.

All this operations take some time, added subsequently. Usually, the main part of this time is used to display the results on the page. But not always.

Give us more details. How many requests to you perform same time? Are there [I]asynchronous[/I] or [I]synchronous[/I]? Which kind of response AJAX gets: a [I]text[/I], a [I]JSON object[/I] or an [I]XML object[/I]? Are you using [I]DOM methods[/I] to display the results or [I]innerHTML[/I]?

A code, or the significant part of it will be also of great help.
Copy linkTweet thisAlerts:
@nanna_govindauthorOct 01.2007 — Thanks for ur reply,

We are actually sending 3 urls as request to SSA.First we are sending one url to SSA.

After getting source code of 1st url in the text format we are sending 2 Url as request to SSA.

After getting source code of 2nd url we are parsing both source codes to retrieve desired values/url.

In the process of parsing we are passing 3 url to SSA,which will go to remote server,connect to database and retrive value from database.

For that DB connection we also wrote some php page,in which DB connection is written and placed in the ftp server.

The important point here is we are sending requests for url1,url2 only once,but we are sending request for url3 many times retriving values for each request.

Now we are using those source codes retrive the desired values and display them in the webpage using .innerHtml and we have used asynchronous request(true),with xmlrequest.

We also used synchronous request(false),but we didn't got any source code.

so,please help us.
Copy linkTweet thisAlerts:
@KorOct 01.2007 — Hm... sounds like a process with too many steps... Can't you send all you need for your urls 3 only once, to avoid the repetition?

Or... can't you use a single AJAX request and let the SSA to do all the jobs? (send 1 to DB, get the response, send a 2 request - based on 1 -, get the response, send the 3 request - based on 1,2 - and repeat this as many times as necessary, than finally send back a single response to the AJAX object).

It is better to let the server-side applications to do as many jobs as possible and use AJAX only once, to send a request and get a response. As I said, javascript is much slower than a server-side language (10X slower than Java, about 30X slower than PHP or ASP, 100X than C++)....
Copy linkTweet thisAlerts:
@nanna_govindauthorOct 01.2007 — Thank you for u reply,


We are actually placed the request for 3rd url inside the while loop.

Each time the url parameter will change and retrieve the corresponding value from the database.

We use that value,manipulate with our coding and display it in the web page.


So,please help us
Copy linkTweet thisAlerts:
@KorOct 01.2007 — According to the information you gave me, there is nothing more I can help you, sorry. You gave me general information, I gave you general ideas.
Copy linkTweet thisAlerts:
@nanna_govindauthorOct 02.2007 — Hi Kor,

Thanks for your ideas,

Here is the code we have applied in our application.
<i>
</i>function rate()
{
var s=new String(window._content.document.URL); <br/>
var intstr_site=s.indexOf('.');
var str_site=s.substring(intstr_site+1,intstr_site+8);
var intstrvalue=str_site.indexOf('.');
str_site=str_site.substring(intstrvalue,0);
if(str_site=='yahoo')
{
var str = s.replace(/&amp;/g,"@" ); <br/>
var url='http://....../parse.php?parse=yahoo&amp;name='+str;
makeRequest(s);//FIRST REQUEST FOR URL
while(source==null)
{
alert("Press Enter To Continue To Display Ratings");
};
var leng=source.length;s
var intyahoo=0,intlastyahoo=0;
var str6=source;
while(source.length&gt;0 &amp;&amp; intyahoo&gt;-1)
{
//PARSING CODE

<i> </i> strlink=strlink.toLowerCase();
<i> </i> strlink=strlink.replace(''',"'");
<i> </i> var intfirst=0,intlast=0;
<i> </i> makeRequest1(url);//SECOND REQUEST FOR URL
<i> </i> while(source1==null)
<i> </i> {
<i> </i> alert("Press Enter To Continue To Display Ratings");
<i> </i> };
<i> </i> obj=source1;
<i> </i> while(source1.length&gt;0 &amp;&amp; intfirst&gt;-1)
<i> </i> {
<i> </i> //PARSING CODE var strval;
<i> </i> var urlpath='http://......function.php?url='+strsubstr;
<i> </i> ajaxFunction(urlpath);//THIRD REQUEST FOR URL
<i> </i> HERE IS THE 3 rd URL WE ARE
<i> </i> REQUESTING MANY TIMES
<i> </i> WHICH IS INSIDE WHILE
<i> </i> LOOP //
<i> </i> while (showvalue==null)
<i> </i> {
<i> </i> alert("Press Enter To Continue To Display Ratings");
<i> </i> };
<i> </i> if (strlink1 == strlink)
<i> </i> {
<i> </i> if(showvalue.indexOf('&lt;td&gt;')&gt;-1&amp;&amp;showvalue.indexOf('&lt;/td&gt;')&gt;-1)
<i> </i> {
<i> </i> var intvalu1=showvalue.indexOf('&lt;td&gt;');
<i> </i> var intvalu2=showvalue.indexOf('&lt;/td&gt;');
<i> </i> strval=showvalue.substring(intvalu1+4,intvalu2);
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> strval=0;
<i> </i> }
var newstr=stryahoo +" " +"&lt;a href='http://.........index.php?show=" + strval + "'

target='_blank'&gt;&lt;font size='2' color='#FFCC33' face='Verdana'

style="visibility:visble;border:solid #000 1px;background-color:

black;background-image:url('http:/........./images/bg.jpg') color="white"&gt;&lt;B&gt;Rating:" +

"" + number + "- Details here.." + "&lt;/B&gt;&lt;/font&gt;&lt;/a&gt;";
str6 = str6.replace(stryahoo , newstr);
window._content.document.getElementById('thelayer').innerHTML=str6;
}
else
{
if (strlink1.indexOf("...") &gt; -1)
{
var str_google2 = strlink1.indexOf("...");
var str_google1 = strlink1.substring(str_google2,0);
if (strlink.length &gt; str_google1.length)
{
strgoogle_value = strlink.substring(str_google2,0);
if (str_google1 == strgoogle_value)
{
if(showvalue.indexOf('&lt;td&gt;')&gt;-1 &amp;&amp; showvalue.indexOf('&lt;/td&gt;')&gt;-1)
{
var intvalu1=showvalue.indexOf('&lt;td&gt;');
var intvalu2=showvalue.indexOf('&lt;/td&gt;');
strval=showvalue.substring(intvalu1+4,intvalu2);
}
else
{
strval=0;
}
var newstr=stryahoo +" " +"&lt;a

href='http://....../index.php?show=" + strval + "' target='_blank'&gt;&lt;font size='2'

color='#FFCC33' face='Verdana' style="visibility:visble;border:solid #000

1px;background-color: black;background-image:url('http://..../images/bg.jpg')

color="white"&gt;&lt;B&gt;Rating:" + "" + number + "- Details here.." + "&lt;/B&gt;&lt;/font&gt;&lt;/a&gt;"; <br/>
str6 = str6.replace(stryahoo, newstr);
window._content.document.getElementById('thelayer').innerHTML=str6;
}
}
}
}
}
};
source1=obj;
showvalue=null;
}
};
source1=null;
source=null;
}
}//end function



function makeRequest(url)
{
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}

<i> </i> if (!http_request)
<i> </i> {
<i> </i> alert('Giving up :( Cannot create an XMLHTTP instance');
<i> </i> return false;
<i> </i> }
<i> </i> try
<i> </i> {
<i> </i> netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
<i> </i> }
<i> </i> catch (e)
<i> </i> {
<i> </i> alert("Permission UniversalBrowserRead denied.");
<i> </i> }

<i> </i> http_request.onreadystatechange = alertContent;
<i> </i> http_request.open('GET', url,true);
<i> </i> http_request.send(null);
}




function alertContent()
{
if (http_request.readyState == 1)
{
if(window._content.document.getElementById('thelayer'))
{
window._content.document.getElementById('thelayer').innerHTML="";
window._content.document.getElementById('thelayer').innerHTML='&lt;table border=0

style="background-color:#000000" &gt;&lt;tr&gt;&lt;td &gt;&lt;font color="white"&gt;&lt;b&gt;Please wait
while ratings are collected ! &lt;/font&gt; &lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
}
else
{
var theNewParagraph =window._content.document.createElement('div');
theNewParagraph.setAttribute('id','thelayer');

<i> </i> theNewParagraph.setAttribute('style','position:absolute;z-index:1000009;width:100%;
<i> </i> left:0;top:0;visibility:visible;border:solid #000

<i> </i> 1px;background-color: #ffffff;');
<i> </i>window._content.document.body.appendChild(theNewParagraph);
<i> </i>window._content.document.getElementById('thelayer').innerHTML='&lt;table border=0

<i> </i> style="background-color:#000000" &gt;&lt;tr&gt;&lt;td &gt;&lt;font color="white"&gt;
<i> </i> &lt;b&gt;Please wait while ratings are collected ! &lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
<i> </i> }
}
if (http_request.readyState == 4 )
{
source=http_request.responseText;
window._content.document.getElementById('thelayer').innerHTML=source;
}
return source;
}



function ajaxFunction(url)
{
if (window.XMLHttpRequest)
{
// Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
// IE
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}

<i> </i> if (!http_request)
<i> </i> {
<i> </i> alert('Giving up :( Cannot create an XMLHTTP instance');
<i> </i> return false;
<i> </i> }
<i> </i> try
<i> </i> {
<i> </i> netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
<i> </i> }
<i> </i> catch (e)
<i> </i> {
<i> </i> alert("Permission UniversalBrowserRead denied.");
<i> </i> }

<i> </i> http_request.onreadystatechange = functiondb;
<i> </i> http_request.open('GET', url,true);
<i> </i> http_request.send(null);
}//end function



function functiondb()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
showvalue=http_request.responseText;
}
}
return showvalue;
}


Hope you have understand what we doing.

Actually we passing url getting source code and parsing that cod and retrieving values and placing in the web page using .innerHtml.

Please help us.
Copy linkTweet thisAlerts:
@nanna_govindauthorOct 03.2007 — Hi Kor,

We have posted the code what we have done in our application.

We are waiting for your reply.

We are in urgent need.Please help us.

Thanking you.
×

Success!

Help @nanna_govind spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...