質問編集履歴
2
プログラムの改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,7 +32,7 @@
|
|
32
32
|
$.ajax({
|
33
33
|
type: "POST",
|
34
34
|
url: "toroku.php",
|
35
|
-
data:{user: user},
|
35
|
+
data:{"user": user},
|
36
36
|
dataType : "json"
|
37
37
|
}).done(function(data) {
|
38
38
|
alert("ok");
|
1
コードの改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,15 +7,40 @@
|
|
7
7
|
となってしまいます。改善点をご教授いただきたいです。
|
8
8
|
|
9
9
|
```index.php
|
10
|
-
$user='aaaa';//別のページからPOSTで受け取った引数
|
10
|
+
<?php $user='aaaa'; ?>//別のページからPOSTで受け取った引数
|
11
|
+
<html>
|
12
|
+
<head>
|
13
|
+
<script src="index.js"></script>
|
14
|
+
</head>
|
15
|
+
<body><!--本体-->
|
16
|
+
<header>
|
17
|
+
<h1 class="title"><a href="index.php">closet</a></h1>
|
18
|
+
<nav class="nav">
|
19
|
+
<ul class="menu-group">
|
11
|
-
<
|
20
|
+
<form>
|
12
|
-
document.getElementById("toroku").onclick=function() {
|
13
|
-
toroku.open('POST', toroku.php);
|
14
|
-
|
21
|
+
<input type="hidden" id=user name="user" value="<?php echo $user; ?>">
|
15
|
-
toroku.send('user=<?php $user ?>');
|
16
|
-
}
|
17
|
-
</
|
22
|
+
</form>
|
18
|
-
<li class="menu-item" id="toroku"><a href=toroku.php>登録</a></li>
|
23
|
+
<li class="menu-item" id="toroku"><a href=toroku.php>登録</a></li>
|
24
|
+
</header>
|
25
|
+
<body>
|
26
|
+
```
|
27
|
+
```index.js
|
28
|
+
$(function(){
|
29
|
+
$("#toroku").click(
|
30
|
+
function(){
|
31
|
+
let user= $("#user").val();
|
32
|
+
$.ajax({
|
33
|
+
type: "POST",
|
34
|
+
url: "toroku.php",
|
35
|
+
data:{user: user},
|
36
|
+
dataType : "json"
|
37
|
+
}).done(function(data) {
|
38
|
+
alert("ok");
|
39
|
+
}).fail((XMLHttpRequest, _textStatus, errorThrown) => {
|
40
|
+
alert("error");
|
41
|
+
});
|
42
|
+
});
|
43
|
+
});
|
19
44
|
```
|
20
45
|
|
21
46
|
```toroku.php
|