Jump to content

jQuery - undefined data being tranfered


KubeR

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/282339-jquery-undefined-data-being-tranfered/
Share on other sites

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) 

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 ?

 

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?

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.

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 ?

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 =  

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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.