我想在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) –