I have some variable:
<input type="text" id="use" />
<div id="app"></div>
I want if ajax success i want to send $('#use').val() into <div>.
I have try like below:
success: function(){
$("#app").val($("#use").val());
}
then:
$("#app").text($("#use").val());
and:
$("#app").replacewith($("#use").val());
But, i get no result. Could you tell me how to do this?
$("#enter").click(function(){
if($("#passlog").valid()){
var params = $("#passlog").serialize();
$.ajax({
type:"post",
url:"process3.php",
data:params,
cache:false,
async:false,
success: function(res){
switch(parseInt(res)){
case "1": //i get value 1 from server side if get 1 do the job below
$("#app").text($("#use").val());
break;
}
},
});
}
});
Divs do not have values, instead you set their HTML:
Or their text:
It’s also worth nothing though that allowing someone to directly enter code into the DOM of your website is a very bad idea.
I noticed you have an extra comma after the success call on your AJAX, try removing it as that could be causing an issue.
If
text()is not working you may have an issue with your AJAX. Do you have an error handler? If not try adding one like the below, and let us know what you get back.}