在ajax中返回多个html数据

在我的ajax代码中


.............

........

success: function(datases) 

               {

 $.ajax({


         url:"checkfitment",

         method: 'POST',

        data: {checkfitment:checkfitment, make:selectedmakes},

        success: function(datas) 

    {

 $(".checkfirmentidmsg").html(datas); 

        }

   }); 


 $.ajax({

 url:"showattributespecification",

 method: 'POST',

 data: {checkfitment:checkfitment , make:selectedmakes},

 success: function(datas) 

        {

        $("#specificationsforms").hide();

        $("#showattributespecificationmsg").html(datas); 

             }

});

以上两个ajax调用主ajax成功结果,两个ajax传递相同的数据但结果不同。


功能


public function checkfitment()

{

 $make = $_POST['make'];

$fiter_products= DB::select(...............);

$countfitment = count($fiter_products);

if($countfitment > '0')

        {

?><span class="checkfit"><input type="checkbox" readonly="readonly" checked="checked" name="fitmentchecked" value="1" /> Fits <?php echo $year. ' '.$make.' '.$model;?> <div class="checkfit-oem"><?php echo  '[OEM '.$bolt_pattern.' '.$rim_width.'Jx'.$rim_diameter.']'; ?></div>


         <style> .mfp-container{ display:none;}

                       .checkFitmentsss{ display:none; position:inherit}

                       [type="checkbox"]:not(:checked), [type="checkbox"]:checked {

    position: absolute;

    opacity:unset  !important;;

</style>


            <?php

}

}

这次结果显示得非常慢,我认为它写在一个函数和一个 ajax 调用中,如何将这两个函数写在一个函数中,如何将这些数据存储在一个变量中?



犯罪嫌疑人X
浏览 99回答 1
1回答

繁花如伊

您能否从服务器端遵循以下方法并使用以下带有数据类型的ajax方法json来接收多个值$.ajax({&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; url&nbsp; &nbsp; &nbsp;: "myurl.php",&nbsp; &nbsp; method&nbsp; : 'POST',&nbsp; &nbsp; datatype : 'json',&nbsp; &nbsp; data&nbsp; &nbsp; : {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params1 : value1,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params2 : value2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; success : function(datas) {&nbsp; &nbsp; &nbsp; $("#elem1").html(data.html1);&nbsp;&nbsp; &nbsp; &nbsp; $("#elem2").html(data.html2);&nbsp; &nbsp; }});&nbsp;myurl.php 服务器端脚本应该如下<?php&nbsp; &nbsp; $return = array();&nbsp; &nbsp; $html1&nbsp; = '';&nbsp; &nbsp; $html2&nbsp; = '';&nbsp; &nbsp; $html1.='<h2>This is a test element</h2>';&nbsp; &nbsp; $html2.='<h2>This is another test element</h2>'&nbsp; &nbsp; $return['html1'] = $html1;&nbsp; &nbsp; $return['html2'] = $html2;&nbsp; &nbsp; echo json_encode($return); exit;?>
打开App,查看更多内容
随时随地看视频慕课网APP