tags:

views:

116

answers:

4

Hi, i got this script, which i found in the web:

<script type="text/javascript">
$(document).ready(
    function () {
     $('a.closeEl').bind('click', toggleContent);
     $('div.groupWrapper').Sortable(
      {
       accept: 'groupItem',
       helperclass: 'sortHelper',
       activeclass :  'sortableactive',
       hoverclass :  'sortablehover',
       handle: 'div.itemHeader',
       tolerance: 'pointer',
       onChange : function(ser)
       {
       },
       onStart : function()
       {
        $.iAutoscroller.start(this, document.getElementsByTagName('body'));
       },
       onStop : function()
       {
        $.iAutoscroller.stop();


       }
      }
     );
    }
);
var toggleContent = function(e)
{
    var targetContent = $('div.itemContent', this.parentNode.parentNode);
    if (targetContent.css('display') == 'none') {
     targetContent.slideDown(300);
     $(this).html('[-]');
    } else {
     targetContent.slideUp(300);
     $(this).html('[+]');
    }
    return false;
};
function serialize(s)
{
    serial = $.SortSerialize(s);
    alert(serial.hash);

};
</script>
<div  class="serializer">
<a href="#" onClick="serialize(); return false;" >serialize all lists</a>


</div>
     <script language="JavaScript" type="text/javascript">var client_id = 1;</script>

at the bottom of the script is the "function serialize", which is called by clicking on the link below. Can someone tell me, how can i send the variable "serial.hash" to a php-file to save it in mysql-database?

many thanks, maschek

A: 

Use Ajax to send request to a PHP script which submits the data to a database. The JQuery documents contain a lot of examples. If you use a HTTP GET request, be warned there is a limit on the amount of data you can pass. This is browser dependant. I would recommend using jQuery.post as the method of sending data.

All the PHP script has to do is read the variables either from $_GET or $_POST (whichever method you use), sanitize them and submit them to the database.

Yacoby
thank you guys for the quick replies. so could i just place jQuery.post into the following?function serialize(s){ serial = $.SortSerialize(s); alert(serial.hash);};The var which i wanna send is already in there, now i would prefer the $_POST method to send it. So would it just be enough place the code from the Link, Yacoby have sent into the "function serialize"and read it out in an php-file?
maschek
A: 

Yes as Yacoby says $.post() or jQuery.post

http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

Shaun Hare
A: 

I placed the code from the link into "function serialize(s)" so it looks like this now:

function serialize(s)

{ serial = $.SortSerialize(s); alert(serial.hash);

var var1 = serial.hash;

$.post("test.php", { myvar1:var1}, function(data){ alert(data.name);

}, "json");

};

But didnt work. What could possibly be wrong with this code?

maschek
A: 

solved it. actually it seems very simple now:

"$.post("test.php",{'func':'serial'},function(data){ alert(data); });"

maschek