Livecode server $_POST for jquery problem

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Livecode server $_POST for jquery problem

Post by francis6425 » Thu Dec 31, 2015 2:50 pm

I've tried using the following script to send field data back to the server using jquery.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/j ... "></script>
<script>
$(document).ready(function(){
$("#submit").click(function(){
var data=$("#loginform").serialize();
$.post("test_post.lc",
data,
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
return false;
});
});
</script>
</head>
<body>
<form id="loginform">
<input type="text" name="email" id="email" value="" placeholder="email">
<br/><br/>
<input type="password" name="pwd" id="pwd" value="" placeholder="password">
<br/><br/>
<input type="submit" value="Submit" id="submit">
</form>
</body>
</html>

I have also created 2 separate file, 1 in lc and the other in php to retrieve the posted data and return it back

test_post.php
<?php
echo 'POST: ';
foreach ($_POST as $key => $value) {
echo $key . '=' . $value . ',';
}
?>

test_post.lc
<?lc
repeat for each key tKey in $_POST
put tKey & "=" & $_POST[tkey] && comma after tDat
end repeat
put "POST:" && tDat
?>

When I post the request to the php file ("test_post.php"), I'm able to retrieve the fields value back.
But when I post the request to the lc file ("test_post.lc"), I'm not able to retrieve any value.
post_to_lc.png
post_to_lc.png (11.54 KiB) Viewed 4820 times
post_to_php.png
post_to_php.png (11.67 KiB) Viewed 4820 times
I've also tried to post the data direct without jquery and both php and lc is able to return the posted data.
Is it a bug for the livecode server or is there any problem on my code ?
Any experts out here please advise.

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Livecode server $_POST for jquery problem

Post by francis6425 » Thu Dec 31, 2015 2:53 pm

Forget to mention that I've also tried the jquery .get method and it is working fine and able to return the submitted data.
Only the jquery post method together with lc server trying to retrieve the $_POST is not working.

SparkOut
Posts: 2857
Joined: Sun Sep 23, 2007 4:58 pm

Re: Livecode server $_POST for jquery problem

Post by SparkOut » Thu Dec 31, 2015 7:38 pm

I know there is or was a bug with POST data to LC server. I thought it was supposed have been fixed? What version of LiveCode Server is running on your server?

http://quality.livecode.com/show_bug.cgi?id=9820 might apply. ( http://quality.livecode.com/show_bug.cgi?id=15173 is marked as duplicate.)
It says the fix was effective in version 6.7.6. In bug #15173 it mentions the default version installed on On-Rev servers is 6.6.5 - but in actual fact my hosting on Tio reports version 6.6.2 in use.

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Livecode server $_POST for jquery problem

Post by francis6425 » Fri Jan 01, 2016 12:34 am

Hi Spark,

Yes confirmed it is the bug and that the version in use by on-rev is 6.6.2.
Since I don't have any choice on the version installed in on-rev, managed to get around it by using ajax with additional line
contentType: "application/x-www-form-urlencoded"

Thanks for hi lighting it out.

Post Reply

Return to “Internet”