KubeR Posted September 21, 2013 Share Posted September 21, 2013 (edited) Hi, well,lately I tried to create a button which transfers the value from the element to another file(.php) through $.get, but when I try to transfer data,it says that it's undefined. the code: l=$("#text_edit").val(); $.get("save.php", { id : "0", c : l },function(data) { alert(data.id); alert(data.c); }); so my question is,why it fails to transfer and the data is undefined ? Edited September 21, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/ Share on other sites More sharing options...
jazzman1 Posted September 21, 2013 Share Posted September 21, 2013 Did you call a $( document ).ready() block ? Try, <script type="text/javascript"> $( document ).ready(function() { l=$("#text_edit").val(); $.get("save.php", { id : "0", c : l },function(data) { alert(data.id); alert(data.c); }); }); </script> Or shortHand: <script type="text/javascript"> $(function () { l=$("#text_edit").val(); $.get("save.php", { id : "0", c : l },function(data) { alert(data.id); alert(data.c); }); }); </script> Also, you should have to know that "0" is not equal to 0 in this comparison: if("0" === 0) Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450575 Share on other sites More sharing options...
KubeR Posted September 21, 2013 Author Share Posted September 21, 2013 (edited) Yep,it is under that block (in it) and about the id,thanks for telling. Edited September 21, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450597 Share on other sites More sharing options...
jazzman1 Posted September 21, 2013 Share Posted September 21, 2013 Can I see the output this data? $(function () { l=$("#text_edit").val(); $.get("save.php", { id : "0", c : l },function(data) { console.log(data); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450598 Share on other sites More sharing options...
KubeR Posted September 21, 2013 Author Share Posted September 21, 2013 (edited) hm...have no idea what it means nor fix this,but here it is: Failed to load resource: the server responded with a status of 406 (Not Acceptable) EDIT: tested it by passing the text in English and as I understood it doesn't accept text in Russian,how can I save text in Russian then ? Edited September 21, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450608 Share on other sites More sharing options...
jazzman1 Posted September 21, 2013 Share Posted September 21, 2013 (edited) tested it by passing the text in English and as I understood it doesn't accept text in Russian I don't believe that to cause the problem. Do you have a .htaccess file placed inside the web tree? EDIT: ops....this { id : "0", c : l } is a small "L" not just a number one "1". Then, what charset encoding are you using? Edited September 21, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450610 Share on other sites More sharing options...
KubeR Posted September 22, 2013 Author Share Posted September 22, 2013 UTF-8 without BOM the .htacess is inside it,well,as I said,I tried to send a file with the word : Test and it passed successfully and showed up on the page. but when I try to pass a much longer and in Russian text,it says it's unacceptable. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450640 Share on other sites More sharing options...
jazzman1 Posted September 22, 2013 Share Posted September 22, 2013 Make sure that everything is speaking utf8. Connection to your database, database/tables collation, apache headers, a form accept-charset attribute. That's your problem. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450654 Share on other sites More sharing options...
kicken Posted September 22, 2013 Share Posted September 22, 2013 My best guess would be that your server is running mod_security and has a rule which is matching your Russian text somehow. You need to either disable mod_security or remove the rule. Check this post for some info: HTTP 406 Error Also note that you probably should be using $.post, not $.get. POST is more semantically correct for saving information, and it has no length restrictions like GET does. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450692 Share on other sites More sharing options...
KubeR Posted September 22, 2013 Author Share Posted September 22, 2013 (edited) My best guess would be that your server is running mod_security and has a rule which is matching your Russian text somehow. You need to either disable mod_security or remove the rule. Check this post for some info: HTTP 406 Error Also note that you probably should be using $.post, not $.get. POST is more semantically correct for saving information, and it has no length restrictions like GET does. Indeed,there was a mod_security and it fixed the problem. but it doesn't save long messages(3000 letters),in php.ini it set to 64M by default,which is enough(?) so what can cause the problem ? Edited September 22, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450701 Share on other sites More sharing options...
jazzman1 Posted September 22, 2013 Share Posted September 22, 2013 Hm.....more than 3000 letters through GET Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450703 Share on other sites More sharing options...
KubeR Posted September 22, 2013 Author Share Posted September 22, 2013 Hm.....more than 3000 letters through GET Post actually,I switched it to post. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450704 Share on other sites More sharing options...
jazzman1 Posted September 22, 2013 Share Posted September 22, 2013 You cannot upload this data to the fileserver or you cannot store it to the database? Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450705 Share on other sites More sharing options...
KubeR Posted September 22, 2013 Author Share Posted September 22, 2013 You cannot upload this data to the fileserver or you cannot store it to the database? Store it in the database Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450707 Share on other sites More sharing options...
jazzman1 Posted September 22, 2013 Share Posted September 22, 2013 Then, you should have to consider to change the current type of this column to MEDIUMTEXT or LONGTEXT. http://dev.mysql.com/doc/refman/5.0/en/blob.html Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450708 Share on other sites More sharing options...
KubeR Posted September 22, 2013 Author Share Posted September 22, 2013 Then, you should have to consider to change the current type of this column to MEDIUMTEXT or LONGTEXT. http://dev.mysql.com/doc/refman/5.0/en/blob.html Works if I set it through phpMyAdmin,but ain't saving through the button. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450710 Share on other sites More sharing options...
jazzman1 Posted September 22, 2013 Share Posted September 22, 2013 Works if I set it through phpMyAdmin,but ain't saving through the button. You are not able to upload this large date, then to store it to your DB. Make sure, there is no an apache rule for a size limits inside .htaccess Also, give us some info of those: (check inside a php.ini file) file_uploads = upload_max_filesize = max_file_uploads = post_max_size = Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450726 Share on other sites More sharing options...
KubeR Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) file_uploads on upload_max_filesize 64M max_file_uploads 20 post_max_size 64M Edited September 23, 2013 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450775 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 Hm....I'm not sure what could be causing this problem. Did you try to upload the data without javascript (just for test)? Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450780 Share on other sites More sharing options...
Solution KubeR Posted September 23, 2013 Author Solution Share Posted September 23, 2013 Hm....I'm not sure what could be causing this problem. Did you try to upload the data without javascript (just for test)?I made a small test : <html> <head></head> <body><form action="get.php" method="post"><textarea type="text" name="a"></textarea><input type="submit" /></form></body> </html>get.php : <? echo $_POST["a"] . " <br /> " . strlen($_POST["a"]); ?>worked without any problems upto 16384 length string.I suppose jQuery has it's own limit in length of post it can send through POST method. Anyhow,I'll just change the method to send the post,from jQuery to HTML. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450791 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 I suppose jQuery has it's own limit in length of post it can send through POST method. I think, AJAX limits you not jQuery, but to be sure 100% make the same request by core javascript. worked without any problems upto 16384 length string. A textarea supports a maxlength attribute in HTML5. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450803 Share on other sites More sharing options...
KubeR Posted September 23, 2013 Author Share Posted September 23, 2013 I think, AJAX limits you not jQuery, but to be sure 100% make the same request by core javascript.True,but couldn't edit the post and fix. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450834 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 True,but couldn't edit the post and fix. What browser are you using for the test? I'm not sure whether you can increase this limit in AJAX. What "Google" says? Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450841 Share on other sites More sharing options...
KubeR Posted September 23, 2013 Author Share Posted September 23, 2013 What browser are you using for the test? I'm not sure whether you can increase this limit in AJAX. What "Google" says?Chrome,but the problem s that the website will be used by the public,means it will need to support any kind of browser. Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450848 Share on other sites More sharing options...
jazzman1 Posted September 23, 2013 Share Posted September 23, 2013 Well, then don't use <textarea></textarea>, use <input type="file">, upload the file into the fileserver, explode the content of this file, delete it and store the content to DB, if this is your personal issue! Quote Link to comment https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/#findComment-1450856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.