开发者

Jquery POST Json return

开发者 https://www.devze.com 2023-02-18 21:09 出处:网络
i have a jquery script, which posts my form. here it is: $(document).ready(function(){ $(\"form#submit\").submit(function() {

i have a jquery script, which posts my form. here it is:

$(document).ready(function(){
$("form#submit").submit(function() {


var an      = $('#an').attr('value');
var betreff = $('#betreff').attr('value');
var text    = $('#text').attr('value');

    $.ajax({
        type: "POST",
        url: "newmsg.php",
        data: "an="+ an +"& betreff="+ betreff +"&text="+ text,
        success: function(){

            $('#window').html(name);                

        }
    });
return false;
});
});

my newmsg.php file

<?php if($_POST['an']=="jo开发者_开发技巧hn") { echo json_encode(array("name"=>"hi john")); } ?>

my problem is, that my php file will not return the name, so my div #window does not post the message

hope you guys understand...

thank you very much


Try

success: function(data){
    var json = $.parseJSON(data);
    $('#window').html(json.name);                
}


this is prob the part you have wrong

$('#an').attr('value');

if id=an is a input it should be done this way

$('#an').val(); 

if id=an is a container it should be done this way

$('#an').html(); 

you'll want to change the rest of these too

var betreff = $('#betreff').attr('value');
var text    = $('#text').attr('value');
0

精彩评论

暂无评论...
验证码 换一张
取 消