我已经回顾了其他主题,但到目前为止我还没有找到任何解决方案。我知道我做错了什么。
这是我的PHP:
header("Content-Type: application/json", true);
echo json_encode((object)array(
"content" =>
$emailAddress
));
以及我的 Ajax 成功部分:
jQuery.ajax({
type: "POST", // HTTP method POST or GET
url: "getemailaddress.php", //Where to make Ajax calls
dataType:"json", // Data type, HTML, json etc.
data:myData, //Form variables
success:function(response){
$("#emailtoinvite").val($(response.content))
},
error:function (xhr, ajaxOptions, thrownError){
//display error message here
}
});
我的输入框得到以下值:
[object Object]
你有什么建议如何解决问题吗?谢谢!
这就是你要求做的:
$(response.content)
是一个表达式,它返回对变量中指定的 CSS 选择器执行查找的 jquery 对象的response.content
实例。
您真正需要的是:
$("#emailtoinvite").val(response.content)
^--- a plain value, not a `$` function call