質問するログイン新規登録

質問編集履歴

1

2015/02/13 02:55

投稿

saori92
saori92

スコア139

title CHANGED
File without changes
body CHANGED
@@ -1,59 +1,57 @@
1
- jqueryとPHPを使ってフォームが無くても、テキストフィールドを送信する方法はないでしょうか?
2
-
3
- こちらで作成したコードは下記のとおりです。
4
-
5
- HTML:
6
- ```lang-<ここに言語を入力>
7
- <div id="form1" class="enviar"> <p>
8
- URL:
9
- <input type="text" name="url" id="url" />
10
- <p> JSON:
11
- <textarea name="json" id="json" cols="45" rows="5"></textarea>
12
- </p>
13
- <p>
14
- <input type="submit" name="send" value="send" />
15
- </p>
16
- </div>
17
-
18
- ```
19
- JQUERY:
20
- ```lang-<ここに言語を入力>
21
- $(function(){
22
- $("#send") .submit(function(){
23
- var json = $("#json") .val();
24
- var url = $("#url") .val();
25
- var s = {
26
- "json":json
27
- }
28
- var u = {
29
- "url":url
30
- }
31
-
32
- $.ajax({
33
- url:u,
34
- type:'post',
35
- data:s,
36
- beforeSend: function (){
37
- $(".status") .html(" alt=\"Loading ....\" />");
38
- },
39
- success:function(data){
40
- $(".status").html(data);
41
- }
42
- });
43
-
44
- });
45
- })
46
- ```
47
- PHP:
48
- ```lang-<ここに言語を入力>
49
- include ('conection.php');
50
- $arr = json_decode($_POST['json'],true);
51
- if ($_POST['json']>NULL){
52
- mysql_query("INSERT INTO liciteiro.clientes(client_id,client_descricao,client_razaosocial,client_endereco,client_cidade,client_estado,client_telefone) VALUES ('".$arr[0]['client_id']."','".$arr[0]['client_descricao']."','".$arr[0]['client_razaosocial']."','".$arr[0]['client_endereco']."','".$arr[0]['client_cidade']."','".$arr[0]['client_estado']."','".$arr[0]['client_telefone']."')")or die(mysql_error());
53
- }
54
- else {
55
- die(mysql_error());
56
- }
57
- ```
58
-
1
+ jqueryとPHPを使ってフォームが無くても、テキストフィールドを送信する方法はないでしょうか?
2
+
3
+ こちらで作成したコードは下記のとおりです。
4
+
5
+ HTML:
6
+
7
+ <div id="form1" class="enviar"> <p>
8
+ URL:
9
+ <input type="text" name="url" id="url" />
10
+ <p> JSON:
11
+ <textarea name="json" id="json" cols="45" rows="5"></textarea>
12
+ </p>
13
+ <p>
14
+ <input type="submit" name="send" value="send" />
15
+ </p>
16
+ </div>
17
+
18
+ JQUERY:
19
+
20
+ $(function(){
21
+ $("#send") .submit(function(){
22
+ var json = $("#json") .val();
23
+ var url = $("#url") .val();
24
+ var s = {
25
+ "json":json
26
+ }
27
+ var u = {
28
+ "url":url
29
+ }
30
+
31
+ $.ajax({
32
+ url:u,
33
+ type:'post',
34
+ data:s,
35
+ beforeSend: function (){
36
+ $(".status") .html(" alt=\"Loading ....\" />");
37
+ },
38
+ success:function(data){
39
+ $(".status").html(data);
40
+ }
41
+ });
42
+
43
+ });
44
+ })
45
+
46
+ PHP:
47
+
48
+ include ('conection.php');
49
+ $arr = json_decode($_POST['json'],true);
50
+ if ($_POST['json']>NULL){
51
+ mysql_query("INSERT INTO liciteiro.clientes(client_id,client_descricao,client_razaosocial,client_endereco,client_cidade,client_estado,client_telefone) VALUES ('".$arr[0]['client_id']."','".$arr[0]['client_descricao']."','".$arr[0]['client_razaosocial']."','".$arr[0]['client_endereco']."','".$arr[0]['client_cidade']."','".$arr[0]['client_estado']."','".$arr[0]['client_telefone']."')")or die(mysql_error());
52
+ }
53
+ else {
54
+ die(mysql_error());
55
+ }
56
+
59
57
  しかし、このコードでは何も送信することができません。ご教示のほどお願いします!