开发者

ajax from jquery issue

I have a small question, if anybody could help me. Why I can't see the result of an ajax request in my source c开发者_Go百科ode? I use ajax from jQuery all is working fine as I see the desired result on the page. But when I want to look in the source code is like. Between div's should be the result. And that's why I can't get a .click() code event from a element that is created by the ajax. Thank's


This is normal. The "View source" view will not show any modifications to the DOM that occurred after loading the page.

Use a tool like Firebug or Chrome's Developer Tools to inspect the DOM "live".


Javascript code is dynamically fetched/generated. To see it you need to use something like Google Chrome's "inspect element" facility.


I'm guessing you're referring to the view of the HTML source.

The HTML source your browser displays will be what it was when the page was loaded, so any DOM manipulations will not be reflected in this.

If you use a developer tool such as Firebug or IE developer toolbar, you should be able to select your new element by click using the tool to view the source HTML.


You could add the word "debugger" in the click event. when it executes firebug and chrome tool will stop in that point.


For your original question as mentionned above you will need a tool such as firebug to view the actual state of the DOM.

Now, based on the question you've asked in your comment to @pekka, i think live() might be what you are looking for.

Basically what this function does is bind an event to all the matching elements, But the difference with $.click() is that it also works on elements added dynamically at run time (ie elements added via ajax for example. see http://api.jquery.com/live/ for details.)

still based on your comment @pekka, i would suggest trying something like

$("#link").live('click', function(){alert("asd");})


Very important to your understanding is that jQuery does not generate "html" code for the .click() event. So you will never see the onclick as shown below.

<input type='button' onclick='alert(asd);' />

BTW that code might be what you where looking for based on your comment to @pekka

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜