开发者

using ajax in a page loaded by ajax

开发者 https://www.devze.com 2023-02-25 03:57 出处:网络
i have a page loaded via jquery tabs ajax, i have a form within this page that i want to show form response via ajax. response is loading from this code:

i have a page loaded via jquery tabs ajax, i have a form within this page that i want to show form response via ajax. response is loading from this code:

$('#whois').submit(function() { 
    $.ajax({
        data: $('#whois').serialize(), 
        cache:false,
        type: "POST", 
        url: $('#whois').attr('/lib/domainchecker.php'), 
        success: function(response) { 
            $('#reply').html(response); 
        }
    });
    return false;
);

but my form submit to parent page instead of /lib/domainchecker.php. so i see headers of my page instead of response!

any idea what m开发者_开发技巧akes this happen?


When you are loading content on the page via AJAX and you need to apply events to the loaded content you need to use the jquery live().

  $('#whois').live('submit', function() { 
$.ajax({
    data: $('#whois').serialize(), 
    cache:false,
    type: "POST", 
    url: $('#whois').attr('/lib/domainchecker.php'), 
    success: function(response) { 
        $('#reply').html(response); 
    }
});

This of course goes on the main host page rather than the loaded content page.


problem is solved, no thing related to loading page via ajax but there was an error with code, i shouldn't post to $('#whois').attr('/lib/domainchecker.php') but just '/lib/domainchecker.php'

corrected code:

  $('#whois').live('submit', function() { 
$.ajax({
    data: $('#whois').serialize(), 
    cache:false,
    type: "POST", 
    url: '/lib/domainchecker.php', 
    success: function(response) { 
        $('#reply').html(response); 
    }
});
0

精彩评论

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