Send array with ajax request to php

前端 未结 5 847
逝去的感伤
逝去的感伤 2021-02-08 03:37

I created array like this [\"9\", \"ques_5\", \"19\", \"ques_4\"]. Now I want to send it from JS to PHP but I\'m not getting proper results. My JS code is:

5条回答
  •  独厮守ぢ
    2021-02-08 04:10

    I would like to share a complete example that works for me in order to avoid making each JavaScript function for each PHP function

    // on the HTML side a simple JavaScript call from a link

     test
    
    php function response here!

    // on JavaScript side

    function CargaZona(fc, div, params) {
        var destino = "#" + div;
        var request = $.ajax({
            url : "inc/phpfunc.php",
            type : "POST",
            data : {
                fc : fc,
                params : JSON.stringify(params)
            },
            dataType : "html"
        });
    
        request.done(function (msg) {
            $(destino).html(msg);
        });
    
        request.fail(function (jqXHR, textStatus) {
            alert("Request failed: " + textStatus);
        });
    }
    

    // on phpfunc.php page

    
    

提交回复
热议问题