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 <michaell...@gmail.com> 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 <amitsh...@gmail.com> 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 <rushi...@gmail.com> 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 <foreigne...@gmail.com> 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:
>
> > > > <h3>Some heading</h3>
> > > > <script type="text/javascript">
>
> > > > //Some javascript code
>
> > > > </script>

Reply via email to