【发布时间】:2015-02-28 19:25:12
【问题描述】:
我正在尝试将我从早期的 ajax 调用中存储的现有 xml 文档修改为名为“XML”的全局变量。
现在,我试图将 xml 文档中的标题更改为用户想要更改的任何内容。出于某种原因,在我的 ajax put 调用之后,我不断收到“未捕获的类型错误:非法调用”,但是我的成功函数执行了。我的代码如下:
$("#saveButton").click(function(event) {
var url = links[$("#nameInput").val()]; //the url of the xml file to be modified
changeXML(XML); //XML is global variable where i stored the xml file from 'GET' call earlier
$.ajax({
url: url,
data: XML,
type: 'PUT',
dataType: 'xml',
success: window.location.reload()
});
});
function changeXML(xml){
var title = $("#titleInput").val();//obtains user input for title change
$(xml).find('title').first().text(title);//changes title to what user entered
}
我保存的全局变量xml文件实际上正在被修改,但是在重新加载窗口时,我发现应该放入更改的xml文件没有改变,只是局部变量一个。我做错了什么?
【问题讨论】:
标签: javascript jquery ajax xml put