Ajax 請求資料

來源:互聯網
上載者:User

標籤:style   blog   io   ar   sp   for   java   on   資料   

----------------------------html-------------------------    <ul class="forminfo"  id="attrContent">       <li  id="select_id"><label>商品類型<b>*</b></label>      <div class="vocation">       <select id="type_id" name="GoodsAttr[type_id]" class="select1">             <option value="" selected>選擇類型</option>       <?php foreach ($typeData as $v): ?>                   <option value="<?php echo $v[‘id‘]; ?>">                     <?php echo $v[‘type_name‘]; ?>                   </option>               <?php endforeach; ?>    </select>    </div>    </li>             </ul>----------------------------------JQ 代碼-----------------------//根據類型擷取對應的屬性    $("#type_id").change(function(){    // 擷取當前類型的id    var type_id = $(this).val();    if(type_id > 0)    {            //刪除之前的所有    $("#select_id~li").remove();        //請求ajax    $.ajax({    type : "GET",    url  : "__CONTROLLER__/ajaxGetAttrForm/type_id/"+type_id,    dataType : "json",    success : function(data)    {    // 在這處理伺服器返回的資料    var html = ‘‘;    $(data).each(function(k,v){    // 迴圈每一行是一個li,li中有兩個欄位,第一個裡是屬性的名字,第二個裡是表單元素    //<label>招聘企業<b>*</b></label>    html += ‘<li>‘;    html += ‘<label>‘;    html += v.attr_name;   // 屬性名稱        html += ‘<b>*</b></label>‘;    // 如果屬性是唯一屬性    if(v.attr_type == 0)    {    // 如果沒有可選值就輸出文字框    if(v.attr_value == "")    {    html += "<input type=‘text‘ name=‘GoodsAttr["+v.id+"]‘ width=‘344px‘ class=‘dfinput‘  />";    }    else    {       html += "<div class=‘vocation‘>";    html +="<div class=‘uew-select‘>";        html +="<select class=‘select1‘ name=‘GoodsAttr["+v.id+"]‘>";    // 把可選值轉化成數組    var arr = v.attr_value.split(",");    for(var i=0; i<arr.length; i++)    {      html += "<option  value=‘"+arr[i]+"‘>"+arr[i]+"</option>";    }    html += "</select></div></div>";    }    }    else    {    // 單選的屬性    html +="<div class=‘vocation‘>";    html +="<div class=‘uew-select‘>";    html += "<a   href=‘javascript:;‘ >[+]</a>";    html += "<select style=‘width: 345px;opacity:1;border: 1px solid #bcbcbc;‘ class=‘select1‘ name=‘GoodsAttr["+v.id+"][]‘>";    var arr = v.attr_value.split(",");    for(var i=0; i<arr.length; i++)    {    html += "<option  value=‘"+arr[i]+"‘>"+arr[i]+"</option>";    }    html += "</select>";        html +="</div>";        html +="</div>";    }    html += ‘</li>‘;    });         $("#attrContent").append(html);    }    });    }    else    {    // 如果沒有選擇類型就清空   刪除第一個li後所有兄弟元素    $("#select_id~li").remove();    }    });--------------------控制器---------------------------------------#Ajax擷取屬性public function ajaxGetAttrForm($type_id){      // 根據類型的ID取出這個類型中所有的屬性$m = M(‘Attribute‘);$data = $m->where(‘type_id=‘.$type_id)->select();echo json_encode($data);}

  

Ajax 請求資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.