[jQuery] Re: Executing javascript that comes inside an AJAX response

2009-03-27 Thread Amit Shah

thanks mkmanning,
but i do not using jquery now, i using prototype now.
anyway i have moved the script to main page. will try another time.

On Mar 27, 1:42 am, mkmanning  wrote:
> Did you try my suggestion?
> --
> Put this div in your main page:
> 
> --
> Put this script in your main page (essentially what you have already,
> fix the url for your server):
> $(document).ready(function(){
>          $.ajax({
>                          type:"GET",
>                          url:"/testajax.html",
>                          dataType: "html",
>                          success:
>                                          function(data, status)
>                                          {
>                                                           
> $('#test').html(data);
>                                          }
>                         });
>
> });
>
> --
> Put this in your ajax response (call it testajax.html or whatever
> you're calling):
> 
> function sometesting(){
>         alert('this works');}
>
> //attach event with jQuery, even though there's no 'jQuery'
> //on this page (it will inherit from the page it's injected in)
> $('#tdtest').mouseover(sometesting);
> 
>
> 
>         
>                 Inline (bad practice) 
> works td>
>                 Attached with jQuery (good practice) 
> works tr>
>         
> 
> --
>
> So there's a function in the response ajax called sometesting(). It's
> called in two ways:
> by an inline mouseover, and by a jQuery selector (take your pick)--
> both methods are on the ajax page.
>
> No higher power need be invoked.
>
> On Mar 26, 12:53 pm, Amit Shah  wrote:
>
> > oh god.
>
> > i got a function sometesting() in the ajax response text ok? not in
> > calling main page. it's in response html data from ajax.
> > in response there is a table. in table there is a td and on td
> > mouseover event i call that function to highlight some fields.
>
> > now the function cam from response text. ok? read properly, the
> > response text is cam in main page div tag now.
> > if i call the function from main page anywhere it works.
> > but the actual even that is on mouse over of that td in response text
> > it don't works. it says not define.
>
> > now ?
>
> > On Mar 27, 12:10 am, James  wrote:
>
> > > What do you mean? Could you provide an example of the content of your
> > > response and what you want to do with it?
>
> > > You cannot call a function from inside the response html data before
> > > it reaches the browser. It has to reach the browser first because the
> > > browser does the Javascript work. If you want to do it before then,
> > > you'd have to do it server-side before sending the response.
>
> > > On Mar 26, 2:14 am, Amit Shah  wrote:
>
> > > > you didn't get it.
> > > > i mean the function written in response text. which has be evaluated.
> > > > can be called only from the main script. not from inside the responsed
> > > > html data.
>
> > > > On Mar 24, 8:07 pm, mkmanning  wrote:
>
> > > > > If you're going to use jQuery, you have to be careful about writing
> > > > > code that then doesn't use jQuery. In this case, you're ajax call
> > > > > would have worked fine, if you had stuck with injecting the response
> > > > > into the DOM with jQuery, as it automatically evals scripts in a
> > > > > response with dataType of 'html'.
>
> > > > > Change:
> > > > > contentDiv.innerHTML = data
>
> > > > > to (with the appropriate selector for your div):
> > > > >  $('div').html(data);
>
> > > > > On Mar 24, 3:44 am, Amit Shah  wrote:
>
> > > > > > it's not working.
>
> > > > > > well eval(responseText); don't works.
>
> > > > > > cells = divResult.getElementsByTagName("script");
> > > > > >                         alert(cells.length);
> > > > > >                         for (var i = 0; i < cells.length; i++)
> > > > > >                         {
> > > > > >                

[jQuery] Re: Executing javascript that comes inside an AJAX response

2009-03-26 Thread Amit Shah

oh god.

i got a function sometesting() in the ajax response text ok? not in
calling main page. it's in response html data from ajax.
in response there is a table. in table there is a td and on td
mouseover event i call that function to highlight some fields.

now the function cam from response text. ok? read properly, the
response text is cam in main page div tag now.
if i call the function from main page anywhere it works.
but the actual even that is on mouse over of that td in response text
it don't works. it says not define.

now ?

On Mar 27, 12:10 am, James  wrote:
> What do you mean? Could you provide an example of the content of your
> response and what you want to do with it?
>
> You cannot call a function from inside the response html data before
> it reaches the browser. It has to reach the browser first because the
> browser does the Javascript work. If you want to do it before then,
> you'd have to do it server-side before sending the response.
>
> On Mar 26, 2:14 am, Amit Shah  wrote:
>
>
>
> > you didn't get it.
> > i mean the function written in response text. which has be evaluated.
> > can be called only from the main script. not from inside the responsed
> > html data.
>
> > On Mar 24, 8:07 pm, mkmanning  wrote:
>
> > > If you're going to use jQuery, you have to be careful about writing
> > > code that then doesn't use jQuery. In this case, you're ajax call
> > > would have worked fine, if you had stuck with injecting the response
> > > into the DOM with jQuery, as it automatically evals scripts in a
> > > response with dataType of 'html'.
>
> > > Change:
> > > contentDiv.innerHTML = data
>
> > > to (with the appropriate selector for your div):
> > >  $('div').html(data);
>
> > > On Mar 24, 3:44 am, Amit Shah  wrote:
>
> > > > it's not working.
>
> > > > well eval(responseText); don't works.
>
> > > > cells = divResult.getElementsByTagName("script");
> > > >                         alert(cells.length);
> > > >                         for (var i = 0; i < cells.length; i++)
> > > >                         {
> > > >                                 alert(cells[i].innerHTML);
> > > >                             eval(cells[i].innerHTML);
> > > >                     }
> > > >                     sometesting(5);
>
> > > > is working.
> > > > but when the function sometesting() being called somewhere from
> > > > ajaxresponse text, browser gives error. both ie and firefox.
>
> > > > On Mar 15, 7:47 am, NightWatchman  wrote:
>
> > > > > To execute javascript code returned by the server you need to use the
> > > > > javascript eval function on the string of script returned from the
> > > > > server. As far as I know changing the content of a div to a javascript
> > > > > block won't cause that javascript code to execute.
>
> > > > > I think you need to change:
>
> > > > > contentDiv.innerHTML = data;
>
> > > > > to
>
> > > > > eval(data);
>
> > > > > On Mar 14, 3:12 pm, Foreigner  wrote:
>
> > > > > > Hi,
> > > > > > I'm trying to use jQuery to get some HTML with Javascript using 
> > > > > > AJAX.
> > > > > > My response gets inserted into the contentDiv element but my
> > > > > > javascript inside the response doesn't get executed as the
> > > > > > documentation says (http://docs.jquery.com/
> > > > > > Specifying_the_Data_Type_for_AJAX_Requests).
>
> > > > > > Here goes my function with AJAX call:
>
> > > > > > function loadHtml(obj)
> > > > > > {
> > > > > >         if(obj.className == "menuItem")
> > > > > >         {
> > > > > >                 $.ajax({
> > > > > >                                  type:"GET",
> > > > > >                                  url:"content/" + obj.id + ".html",
> > > > > >                                  dataType: "html",
> > > > > >                                  success:
> > > > > >                                          function(data, status)
> > > > > >                                          {
> > > > > >                                                   
> > > > > > contentDiv.innerHTML = data;
> > > > > >                                          }
> > > > > >                                 });
> > > > > >         }
>
> > > > > > }
>
> > > > > > My response looks like:
>
> > > > > > Some heading
> > > > > > 
>
> > > > > > //Some javascript code
>
> > > > > > - Hide quoted text -
>
> - Show quoted text -


[jQuery] Re: Executing javascript that comes inside an AJAX response

2009-03-26 Thread Amit Shah

you didn't get it.
i mean the function written in response text. which has be evaluated.
can be called only from the main script. not from inside the responsed
html data.


On Mar 24, 8:07 pm, mkmanning  wrote:
> If you're going to use jQuery, you have to be careful about writing
> code that then doesn't use jQuery. In this case, you're ajax call
> would have worked fine, if you had stuck with injecting the response
> into the DOM with jQuery, as it automatically evals scripts in a
> response with dataType of 'html'.
>
> Change:
> contentDiv.innerHTML = data
>
> to (with the appropriate selector for your div):
>  $('div').html(data);
>
> On Mar 24, 3:44 am, Amit Shah  wrote:
>
> > it's not working.
>
> > well eval(responseText); don't works.
>
> > cells = divResult.getElementsByTagName("script");
> >                         alert(cells.length);
> >                         for (var i = 0; i < cells.length; i++)
> >                         {
> >                                 alert(cells[i].innerHTML);
> >                             eval(cells[i].innerHTML);
> >                     }
> >                     sometesting(5);
>
> > is working.
> > but when the function sometesting() being called somewhere from
> > ajaxresponse text, browser gives error. both ie and firefox.
>
> > On Mar 15, 7:47 am, NightWatchman  wrote:
>
> > > To execute javascript code returned by the server you need to use the
> > > javascript eval function on the string of script returned from the
> > > server. As far as I know changing the content of a div to a javascript
> > > block won't cause that javascript code to execute.
>
> > > I think you need to change:
>
> > > contentDiv.innerHTML = data;
>
> > > to
>
> > > eval(data);
>
> > > On Mar 14, 3:12 pm, Foreigner  wrote:
>
> > > > Hi,
> > > > I'm trying to use jQuery to get some HTML with Javascript using AJAX.
> > > > My response gets inserted into the contentDiv element but my
> > > > javascript inside the response doesn't get executed as the
> > > > documentation says (http://docs.jquery.com/
> > > > Specifying_the_Data_Type_for_AJAX_Requests).
>
> > > > Here goes my function with AJAX call:
>
> > > > function loadHtml(obj)
> > > > {
> > > >         if(obj.className == "menuItem")
> > > >         {
> > > >                 $.ajax({
> > > >                                  type:"GET",
> > > >                                  url:"content/" + obj.id + ".html",
> > > >                                  dataType: "html",
> > > >                                  success:
> > > >                                          function(data, status)
> > > >                                          {
> > > >                                                   contentDiv.innerHTML 
> > > > = data;
> > > >                                          }
> > > >                                 });
> > > >         }
>
> > > > }
>
> > > > My response looks like:
>
> > > > Some heading
> > > > 
>
> > > > //Some javascript code
>
> > > > 


[jQuery] Re: Executing javascript that comes inside an AJAX response

2009-03-24 Thread Amit Shah

it's not working.

well eval(responseText); don't works.

cells = divResult.getElementsByTagName("script");
alert(cells.length);
for (var i = 0; i < cells.length; i++)
{
alert(cells[i].innerHTML);
eval(cells[i].innerHTML);
}
sometesting(5);


is working.
but when the function sometesting() being called somewhere from
ajaxresponse text, browser gives error. both ie and firefox.

On Mar 15, 7:47 am, NightWatchman  wrote:
> To execute javascript code returned by the server you need to use the
> javascript eval function on the string of script returned from the
> server. As far as I know changing the content of a div to a javascript
> block won't cause that javascript code to execute.
>
> I think you need to change:
>
> contentDiv.innerHTML = data;
>
> to
>
> eval(data);
>
> On Mar 14, 3:12 pm, Foreigner  wrote:
>
> > Hi,
> > I'm trying to use jQuery to get some HTML with Javascript using AJAX.
> > My response gets inserted into the contentDiv element but my
> > javascript inside the response doesn't get executed as the
> > documentation says (http://docs.jquery.com/
> > Specifying_the_Data_Type_for_AJAX_Requests).
>
> > Here goes my function with AJAX call:
>
> > function loadHtml(obj)
> > {
> >         if(obj.className == "menuItem")
> >         {
> >                 $.ajax({
> >                                  type:"GET",
> >                                  url:"content/" + obj.id + ".html",
> >                                  dataType: "html",
> >                                  success:
> >                                          function(data, status)
> >                                          {
> >                                                   contentDiv.innerHTML = 
> > data;
> >                                          }
> >                                 });
> >         }
>
> > }
>
> > My response looks like:
>
> > Some heading
> > 
>
> > //Some javascript code
>
> > 


[jQuery] Question Regarding Superfish

2009-01-21 Thread Amit Shah

Hi,

I am trying to use Superfish Jquery menu in IE6.

It all works fine except that the menu which have sub menus displays 2
arrows next to the text.

I am using the following code:

// initialise Superfish


$(document).ready(function(){
$("ul.sf-menu").superfish();
});



Can someone help me out?

Thanks in advance.

Kind Regards,

Amit Shah