简体   繁体   English

使用ajax和jquery将数组发送到codeigniter(php)控制器,并在现有已加载页面上加载页面(在任何div中)

[英]sending array to codeigniter (php) controller using ajax and jquery and load page on existing loaded page (in any div)

function showmypage(calculated){

    var sorteddata = JSON.stringify(calculated);
    myurl = URL + 'personalloan/getPLOffersbyfilter/eligibility';
    var request = $.ajax({
        url: myurl,
        method: 'POST',
        data: {data:sorteddata},
        dataType: 'html'
        }).done(function(msg){
    $(".divoffersfilter").load(myurl);//here is error
    console.log(msg);
    });

}

I want to send array (calculated is array name) to the controller and this and load a dynamic PHP page using content in that array. 我想将数组(计算为数组名)发送给控制器,然后使用该数组中的内容加载动态PHP页面。 But, here it treats ".load()" function separately. 但是,这里将“ .load()”功能分开对待。 the ajax is processing the request and giving back the response but the response is not loaded on view file . ajax正在处理请求并返回响应,但是响应未加载到视图文件中

Note that you are making two ajax requests to the same URL. 请注意,您正在向同一URL发出两个Ajax请求。

The first one is with the code 第一个是代码

var request = $.ajax({
     url: myurl,
     ...

The second ajax call is in your .done block. 第二个ajax调用在您的.done块中。

$(".divoffersfilter").load(myurl);

The .load() function is shorthand that essentially amounts to this. .load()函数是.load()

$.ajax({
        url: myurl,
        method: 'GET',
        success: function(data){
                $(".divoffersfilter").html = data;
            }
        });

Without seeing the code that executes at the URL it is not possible to provide advice on which ajax approach to use. 如果没有看到在URL上执行的代码,就无法提供有关使用哪种Ajax方法的建议。 But you probably should not use both. 但是您可能不应该同时使用两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM