javascript - PHP / Ajax cannot send value -


i have problem ajax , php.i have next code

$("form").submit(function() {  var poruka = $("#poruka").val();   $.ajax({         type: "get",         url: "/ajax/gather/send/"+ poruka + "/'.$id.'",         success: function(){          loaduj('.$id.');          alert("your message "+poruka);         },         error: function(){             alert("fail");         }     }); }); 

"poruka" message , it's taken form

<form action='javascript:;'> <input type='text' name='poruka' id='poruka' placeholder='poruka..' style='width:100%;'> <input type='button' name='button' hidden> </form> 

and when try send php won't insert database :

php code :

$text = $_post['text']; $id = $_post['id']; if($text != ""){   mysql_query("insert messages (text,id2) values ('$text','$id')") or     die(mysql_error()); } 

and can't work..how can fix ? thanks

you use post instead of get. in ajax form specify use get, in php use $_post superglobal.

change $_post $_get in php code , should work :)

also if not specify method in tag, default get.

from experience, in case if data form not written/updated in/to database use

echo mysql_error(); 

after mysql query , open developer tools on browser , inspect in network panel. developer tools can opened using f12 , ctrl+shift+i if f12 not working due coffee spilled on it. network panel shows data being sent, method used , every other detail of network call. there can see response of server side script in case return mysql error message because echo'ed out.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -