Jump to content

jQuery - undefined data being tranfered


Go to solution Solved by 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 ?

Edited by KubeR
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 ?

Edited by KubeR

 

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 by jazzman1

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.

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 ?

Edited by KubeR

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 =  

  • Solution

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.

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.