【发布时间】:2020-07-25 09:07:52
【问题描述】:
我想通过ajax将数据从js传递到php,但是即使我传递了一些数据,输出也是一个空数组。请帮忙。
<html>
<head>
<title></title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
</body>
<script>
$.ajax({
url:"trialphp.php",
data:{name:"bhanu",
caste:"arora"},
success:function(res){
console.log(res);
}
});
</script>
</html>```
**trialphp.php**
<?php
echo(json_encode($_GET));
?>
【问题讨论】:
-
方法在哪里?
$.ajax({ url:"trialphp.php",method:'POST'或method:'GET'并在方法后添加type:'json' -
您的代码运行良好。所以不确定你的问题是什么。
标签: javascript php html ajax