在ajax中怎么给div赋值,如何在Ajax中添加DIV标签

我想在ajax中插入div标签,但我无法弄清楚如何。到目前为止,这是我的代码:如何在Ajax中添加DIV标签

function userLogin(){

var email = $("#login_username_text").val();

var password = $("#login_password_text").val();

var login_url = connect_url+'retrieveUser.php?email='+email+"&password="+password;

$.ajax({

type: 'GET',

url: login_url,

async: true,

jsonpCallback: 'userCallback',

contentType: "application/json",

dataType: 'jsonp',

success: function(json) {

is_logged = (json[0].logged==0)?false:true;

alert(is_logged);

alert(email);

alert(password);

if(is_logged==false){

alert ("Invalid Username and Password"); //I want to change

//this into a div tag so that it will be displayed on the page itself and so that

//I can add CSS codes here

}

},

error: function(e) {

}

});

}

我试过document.getElementById('login_invalid').innerText = 'Invalid Username and Password.';但没有工作...任何想法?

谢谢!

2013-02-05

ninpot18

+0

你的网页上是否有ID为login_invalid的div? –

+0

console.log(is_logged),让我们知道结果。编辑:由于您已经使用jQuery,使其$(“#login_invalid”)。html(“无效”);而不是使用getElementById。 –

+0

我会建议[寻找一些基本的DOM操作教程](https://www.google.nl/search?q=dom+manipulation+tutorial+jquery) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值