使用ajax在多个页面上发布一篇文章

make a post in several pages using ajax

本文关键字:布一篇 文章 ajax 使用      更新时间:2023-09-26

简而言之,我有以下功能:

$(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 `&` sepparating 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

为什么不试试这样的东西?

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); 
        } 
    });
});