我有一个包含以下内容的JSON文件:
{"users":["john","peter"]}
我尝试做一个Ajax请求,它返回users数组中的两个名字,直到现在一切正常,但是,当我尝试编辑JSON文件时,无论是使用PHP还是手动,让我说我再向用户数组添加两个名称,如下所示:
{"users":["john","peter","George","Robert"]}
我保存JSON文件,重新加载页面,我再次尝试执行ajax请求,但由于某种原因,它返回了我添加两个新名称之前的两个名称。而不是返回
["john","peter","George","Robert"] it does return ["john","peter"]
为什么会发生这种情况?
这是我的Ajax请求:
var request = new XMLHttpRequest();
request.open("GET","../file/data.json",true);
request.send();
request.onload = function(){
var data = JSON.parse(request.responseText);
console.log(data);
}
答案 0 :(得分:0)
使用jQuery
import matplotlib.pyplot as plt
import numpy as np
import itertools
x1 = np.random.binomial(5100,0.5,51100)
y1 = np.random.binomial(5000,0.7,51100)
x2 = np.random.binomial(5000,0.5,51100)
y2 = np.random.binomial(5000,0.7,51100)
xmin,xmax,xnum = 2350,2700,50
ymin,ymax,ynum = 3350,3700,50
xx,yy=np.mgrid[xmin:xmax:xnum*1j,ymin:ymax:ynum*1j]
def closest_idx(x,y):
idcs = np.argmin((xx-x)**2 + (yy-y)**2)
i_x,i_y = np.unravel_index(idcs, (xnum,ynum) )
return i_x,i_y
def calc_count( xdat,ydat ):
ct = np.zeros_like(xx)
for x,y in itertools.izip(xdat,ydat):
ix,iy = closest_idx(x,y)
ct [ix,iy] += 1
return ct
ct1 = calc_count( x1,y1 )
ct2 = calc_count( x2,y2 )
def color_mix( c1 , c2 ):
cm=np.empty_like(c1)
for i in [0,1,2]:
cm[i] = (c1[i]+c2[i])/2.
return cm
dens1 = ct1 / np.max(ct1)
dens2 = ct2 / np.max(ct2)
ct1_color = np.array([1+0*dens1 , 1-dens1 , 1-dens1 ])
ct2_color = np.array([1-dens2 , 1-dens2 , 1+0*dens2])
col = color_mix( ct1_color , ct2_color )
col = np.transpose( col, axes=(2,1,0))
plt.imshow( col , interpolation='nearest' ,extent=(xmin,xmax,ymin,ymax),origin='lower')
plt.show()