$ .ajax无法访问网址

I'm trying to send some data via jquery and $.ajax to a php file. When the page loads, a list of names is retrieved from "bewohner_func.php". This works.

At the end of the list is a form, which is used to add a new Name onto the list. It uses $.ajax to send the data, also to "bewohner_func.php", using a switch to differntiate from displaying or adding the data-. Problem is, when I try to send the form, the script does not include the php file. I can safely say that it's not the php file's fault, as I reduced it to an alert.

$(document).ready(function()
{       
    $("#bew_new").submit(function() 
        {
            var frmData = $("#bew_new").serialize();

            $.ajax({
                    url: "bewohner_func.php",
                    data: frmData,
                    success: function(msg)
                        {
                            $('#bewohnerliste').fadeOut(400);
                            $.get("bewohner_func.php", {'bew_new': '0'}, function(data){
                                $("#bewohnerliste").html(data);
                            });
                            $('#bewohnerliste').fadeIn(400);
                        }
                });
            return false;

        });

});

This is the code for displaying, which does it's job fine:

$(document).ready(function()
{
    $.get("bewohner_func.php", {'bew_new': '0'}, function(data){
        $("#bewohnerliste").html(data);
    });
});

The form:

        <form id="bew_new" class="bew_form" action="bewohner_func.php" method="get">
        <input name="anrede" size="6" value="Anrede" onFocus="if(this.value=='Anrede')this.value=''">
        <input name="name" value="Name" onFocus="if(this.value=='Name')this.value=''">
        <input name="wohnbereich" size="2" value="WB" onFocus="if(this.value=='WB')this.value=''">
        <input type="submit" value="Neu anlegen">
    </form>

It sounds like you are running your submit handler code on page load before form is loaded. If so, submit handler won't be bound to form if it doesn't exist.

You can delegate the handler to an eleemnt, or the document itself, that will be permanent asset in page

TRY:

$("#bewohnerliste").on('submit',"#bew_new",function(){

     var frmData = $(this).serialize();
       $.ajax......
})