开发者

jquery within ajax page

I have been reading around and know that by default jQuery within a the returned html by default does work, but also read that setting the dataType in the ajax requet to "html" shoudl evaluate the jQuery, however it doesn't seem to be doing that.

<script type="text/javascript">
    $(document).ready(function(){
        $('.calendarsubmit').remove();
        $('select[name=typetest]').change(function(){
            var url = '/<?=$eventurlstart?>/'+escape(this.options[this.selectedIndex].value)+'/<?=$mnth?>/<?=$yr?>';
            location.href=url;
        });
        $('select[name=month]').change(function(){
            var url = '/<?=$eventurlstart?>/<?=$type?>/'+escape(this.options[this.selectedIndex].value)+'/<?=$yr?>';
            location.href=url;
        });
        $('select[name=year]').change(function(){
            var url = '/<?=$eventurlstart?>/<?=$type?>/<?=$mnth?>/'+escape(this.options[this.selectedIndex].value);
            location.href=url;
        });
    });
</script>

That is the code that is loaded with the HTML from the page. How do I execute this?

Thanks.

EDIT:

Using live change seems to work:

$('select[name=typetest]').live('change',function(){

The issue I am having now is the .remove(). With or without document ready, it doesn't get called through Ajax.

EDIT 2:

Although the live works, more ajax following, I need a way to update that live function each time the page is called.

EDIT 3:

I just called unbind before recreating the live function, which works great. As for the remove function, I had to add it to the end of my page. Even though it was right after the element, it seemed to get called too soon, so the element wasn't removed. Moving it down made it get removed perfectly.

Thanks everyone that he开发者_运维知识库lped get me to this solution.

EDIT 4:

This actually didn't work. Not sure what happened. Anyways, what I ended up doing is using the live function and having it read the other forms values in jQuery rather than do it via PHP. Still working on the remove issue.


Well, $(document).ready doesn't fire until the HTML is completely parsed, and by that time the AJAX request is over. So it's parsing the javascript, it just doesn't do anything because the event it's attached to isn't firing.


If it's being returned via Ajax, document ready will have already fired.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜