我有javascript代码,可以提取数据并创建一个JSON对象发送到服务器
for (i=0;i<selected.length;i++)
{
if (selected[i].value == "available")
{
//Add item to the selectedjsonObj list
//alert("The new select ID is: " + selected[i].text);
selectedjsonObj[selected[i].text] = selected[i].text;
selected[i].value = "selected";
selectedChange++;
}
}
for (i=0;i<available.length;i++)
{
if (available[i].value == "selected")
{
//Add item to the availablejsonObj list
//alert("The new available ID is: " + available[i].text);
availablejsonObj[available[i].text] = available[i].text;
available[i].value = "available";
availableChange++;
}
}
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("title_msg").innerHTML=xmlhttp.responseText;
// var el = document.getElementById('userid_msg');
if (xmlhttp.responseText=="Updated") {
document.getElementById("title_msg").innerHTML=xmlhttp.responseText;
}
else {
alert("An error occurred saving your changes. Please refresh the page and try again.");
document.getElementById("title_msg").innerHTML=xmlhttp.responseText;
}
}
}
var x=document.forms["cohort"]["title"].value;
if (selectedChange && availableChange) {
xmlhttp.open("GET","/update/cohortfriends?a=" + JSON.stringify(availablejsonObj) + "&s=" + JSON.stringify(selectedjsonObj) + "&t=" + x, true);
xmlhttp.send();
}
if (selectedChange) {
xmlhttp.open("GET","/update/cohortfriends?s=" + JSON.stringify(selectedjsonObj) + "&t=" + x, true);
xmlhttp.send();
}
if (availableChange) {
xmlhttp.open("GET","/update/cohortfriends?a=" + JSON.stringify(availablejsonObj) + "&t=" + x, true);
xmlhttp.send();
}
document.getElementById("save_cohort_friends").innerHTML="No Changes";
在服务器上,我尝试按如下方式读取对象(只显示用于处理JSON对象的代码块之一)
^{pr2}$这是获取的-“list”对象没有属性“read”-错误
删除的\u个朋友=json.load文件(self.request.获取全部(“a”)声明。在
由于我是python和javascript的新手,而且是自学成才的,我确信我在做一些概念上错误的事情。感谢任何帮助。在
get_all
函数返回查询字符串参数a
的所有值。因为您只有一个a
,所以应该使用get
。另外,使用json.loads
将字符串解析为json。在您给
json.load
一个导致此错误的列表。在此外,使用
json.loads
代替json.load
。在试试这个:
根据文件:
所以json.load文件应为类似文件的对象,而不是
list
,而request.get_all
返回该对象。在相关问题 更多 >
编程相关推荐