php网站和Jquery $ .ajax()

The website I'm developing is structured in this way:

It has a function that switches the module for the homepage content when $_GET['module'] is set, example:

function switchmodules()
{
    $module=$_GET['module'];
    switch($module)
    {
        case 'getnews': news(); break;
        default: def();
    }
}

As you can see, this switch calls another function for each module.

For example I wrote getNews() to work in this way:

function getNews()
{
   $id=$_GET['id'];
   if(!id)
   {
       //CODE TO LIST ALL NEWS
   }
   if(isset($id))
   {
       //CODE TO GET ONLY 1 NEWS BY ID
   }

}

So, as you can see I'm not using an unique file for each module; all operations of a module are part of an unique function in which an action is switched again to change the result.

If I want to get a news from database I should use an url like this: ?index.php&module=getnews&id=1

My question now is:
With jQuery and $.ajax() method is there a way to get a news (for example) using this structure based on functions switched by a get? Or do I have to change everything and make a file for each function?

you can simply call the same url via $.ajax(). the only thing which should be changed for axjax calls is that you don't output your layout, but only the news itsself.

in php you can check for an ajax request like

if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {

    // dont output layout
}

If this code is in say 'test.php' you can do:

<script>
    $.get(
        '/test.php',
        {
            module: 'news',
            id: 1
        },
        function( data ) {
            alert( data );
        }
    );
</script>

And js will send GET request to test.php with needed params. Then your server script will decide how to process request.

jQuery

$(document).ready( function() {
    var form = '#my_awesome_form';

    $(form + ' input[type=submit]').click(function(e) {
        e.preventDefault();

        $.ajax({
            type: "GET",
            url: 'index.php',
            data: $(form).serialize(),
            success: function( response ) {
                alert('DONE!');
            }
        });
    });
});

HTML

<form id="my_awesome_form" // OTHERS PROPERTIES //>
    // LOT OF FIELDS HERE //
    <input type="submit" value="Send">
</form>