使用ajax在多个页面中发帖

问题描述 投票:0回答:1

简单来说,我有以下功能:

$(function() { // on load function, everything inside here will not run until the pagehas had time to load  
    $('.filter').click(function(){ 
        document.getElementById("results").innerHTML = 
        "<div class='loading-indication'><img src='ajax-loader.gif' /> &nbsp; Please wait... Loading New Courses...</div>";
        
        var datastring = $('#testform').serialize(); // this will create key/value pairs to send to the phph page like `duration5=5` with a `&` separating each key/value pair 
        $('#display-datastring').html(datastring); // this line is just so you can see the variable being created 
        
        $.ajax({ 
            url: 'fetch_pages.php', 
            type: 'post', 
            data: datastring, 
            success: function(res){ 
                $('#results').html(res); 
            } 
        });     
    }); 
});

结果发布到 url fetch_pages.php。简而言之,我希望将其发布在 fetch_pages.php 和以下函数/usersearch.php

javascript php jquery html ajax
1个回答
0
投票

为什么不尝试这样的事情呢?

var urls = ['fetch_pages.php','functions/usersearch.php'];

$.each(urls, function(i,url){ 
    $.ajax(url, 
    { 
        type: 'POST',
        data: datastring,
        success: function (data) { 
            $('#results').html(data); 
        } 
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.