关于ajax ,php中定义两个变量并赋值,如何用jQuery 的Ajax 获取其中的一个数据

如题所述

可以使用 json   ajax

$.ajax({  
            url: './ajax.php' ,  
            type: 'POST',  
            data: formData,  
            dataType: "json",
            success: function (obj) {
                var msg1= obj['msg1'];
                var msg2= obj['msg2'];
            },  
            error: function (e) {
                alert('error');
                
            }  
        });

PHP

echo json_encode(array('msg1'=>'1','msg2'=>'2'));

不知这是不是你想实现的?

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答