ajax 处理一维数组

前端之家收集整理的这篇文章主要介绍了ajax 处理一维数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
ajax 处理一维数组

http://192.168.137.3:9000/news/onearray/?user=11&password=22&port=33&ip=44&db=55


node2:/django/mysite/mysite#cat urls.py

from django.conf.urls import include,url
from django.contrib import admin
from blog import views as view
from news import views as newview
urlpatterns =( 
url(r'^admin/',admin.site.urls),url(r'^blog/$',view.archive),url(r'^news/',include("news.urls"))


调用news/ 会调用news.urls


node2:/django/mysite/news#cat urls.py
from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^(?P<year>[0-9]{4})/$',views.year_archive),url(r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$',views.month_archive),url(r'^date/$',views.my_view),url(r'^onearray/$',views.onearray),url(r'^displayonearray/$',views.displayonearray),$(function() {
    var _env_bt = $(".content .con #condition .es_2");
    _env_bt.on('click',function() {
        var __user = $(".equipment_sz1").val();
        var __password = $(".equipment_sz2").val();
        var __port = $(".equipment_sz3").val();
        var __ip = $(".equipment_sz4").val();
        var __db = $(".equipment_sz5").val();
        var data = {};
        data.user = __user;
        data.password = __password;
        data.port = __port;
        data.ip = __ip;
        data.db = __db;
        console.log(data);
        var i = 0;
        var successfn = function(jdata) {
            var jdata = eval(jdata);
            $(".gridtable").empty();
            var _HTML = "<tr><th>a1 </th><th>a2</th><th>a3</th><th>a4</th><th>a5</th></tr>";
            $.each(jdata,function(i,val) {
                console.log(jdata[i]);
                console.log(i);
                var len = jdata.length;
                console.log(len);
                if ((i == 0) && (_HTML=='<tr><th>a1 </th><th>a2</th><th>a3</th><th>a4</th><th>a5</th></tr>')){
                    _HTML = _HTML + "<tr>"
					_HTML = _HTML + "<td>" + jdata[i] + "</td>";
                } else if (i == len - 1) {
                    _HTML = _HTML + "<td>" + jdata[i] + "</td></tr>"
                } else {
                    _HTML = _HTML + "<td>" + jdata[i] + "</td>";
                }
                i++;

            });
            console.log(_HTML);
            $(".gridtable").html(_HTML);
        };
        var errorfn = function() {
            alert("数据获取出错");
        };
        $.ajax({
            type: "get",data: data,url: "/news/onearray/",dataType: "json",success: function(d) {
                successfn(d);
            },error: function(e) {
                errorfn(e);
            }
        });
    });

});

猜你在找的Ajax相关文章