Javascript 如何从ajax文本响应中通过id获取值
下面是我的代码,它不工作,如何通过id从数据中响应? 请提供此问题的任何解决方案Javascript 如何从ajax文本响应中通过id获取值,javascript,ajax,Javascript,Ajax,下面是我的代码,它不工作,如何通过id从数据中响应? 请提供此问题的任何解决方案 function loadStatus(uri,id) { waitingDialog.show('Loading', {dialogSize: 'sm'}); $.ajax({ method : "GET", dataType : "text", url : uri, xhrFields : { withCre
function loadStatus(uri,id)
{
waitingDialog.show('Loading', {dialogSize: 'sm'});
$.ajax({
method : "GET",
dataType : "text",
url : uri,
xhrFields : {
withCredentials : true
},
crossDomain : true,
contentType : "application/x-www-form-urlencoded;charset=UTF-8"
}).done(function(msg) {
waitingDialog.hide();
alert(msg);
// getting value by id
var contractID= $msg.filter('#contractID').text();
// getting value by id
var contractID=$(msg).find('#contractID').html();
alert(contractID);
});
return false;
}
这取决于期望从uri获取的数据类型。在done函数中,不应该查询html元素。只是提醒味精,看看你得到了什么
var contractID= $msg.filter('#contractID').text();
$msg未在任何位置定义。。。你使用的下一行
$(msg)
这就是你的意思吗?你能在这里粘贴msg值吗<代码>它不工作不会给出任何线索
标题['Access-Control-Allow-Origin']='*'标题['Access-Control-Request-Method']='*'
在html中添加上述代码,然后检查。这是我在警报弹出框中看到的文本。。。。。。。。。在这里插入标题谢谢macman!数据类型为“text”,我已经看到警报消息显示带有html标记的html文档。我认为您的数据源不正确。这是uri返回的数据还是另一个html文件?这是我在警报弹出窗口中看到的文本。。。。。。。。。在此处插入标题尝试使用此$(“msg”).filter(document.getElementById(“constractId”);那么$(“msg”).filter(document.getElementById(“construcd”)).val()呢;