js sends post request to get json to traverse and write to html

I don't use it very much, just record it for later use. The data is basically processed in the background, just take it and use it directly

function ajax_post(url) {
        $('#html').empty();

		var id = $('#game_id option:selected').val();
        var postData = {
            'id': id,
        };

        $.post(url,postData,function(requst){
            if(requst.code == 1){
                var data = JSON.parse(requst.data);
                var len = getJsonLength(data);//获取json数组长度
                var htmlSpan = "";
                for (var i = 0; i < len; i++ ){
                    htmlSpan += "<label><input type='checkbox' value='" + data[i]['id'] + "' name='type[]'>" + data[i]['name'] + "</label>";
				}
				$('#html').html(htmlSpan);
            }else {
                alert(requst.msg);
            }
        });
    }
    //获取json数组长度
    function getJsonLength(jsonData){
        var jsonLength = 0;
        for(var item in jsonData){
            jsonLength++;
        }
        return jsonLength;
    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324495825&siteId=291194637