ok, thats my code on client-side (i use FCKeditor as wysiwyg):

function doAction() {
  var content = oFCKeditor.GetHTML();
  content = content.replace(/"/g, "\"");

  var title = $('title').value; // input-field

  new Ajax.Request('server.php',
    {
      method: 'post',
      parameters: JSON.stringify({
        method: 'class::function',
        params: [title,encodeURIComponent(content)],
        id: new Date().getTime()
      }),
      onSuccess: function(transport){
        var res = eval('('+transport.responseText+')');
        if (res.error) {
          alert('Error: '+res.error.message);
          return;
        }
        alert(res.result.desc);
      }
    });
}

ok, now some lines of my JSON RPC server:

function hex2str($hex) {
  $str = ''; $loop = 1;
  for($i=0; $i<strlen($hex); $i+=$loop) {
    $chr = substr($hex,$i,1);
    if($chr=='%') { // found next hex
      $chr = substr($hex,$i+1,2);
      $str .= chr(hexdec($chr));
      $loop = 3;
    }
    else { // next char
      $str .= $chr;
      $loop = 1;
    }
  }
  return substr($str,0,strlen($str)-1); // kill the last "=", little
bug
}

try {
  $string = hex2str(file_get_contents('php://input'));
  $objJSON=json_decode($string);
  if(!$objJSON)
    throw new Exception('Not JSON Data...');

  /* do something and fill $obj->buffer with requested data */

  $response->result=$obj->buffer;
} catch (Exception $e) {
  $err=new stdClass;
  $err->message = $e->getMessage();
  $response->error=$err;
}

$response->id=$objJSON->id;

echo json_encode($response);

that is all, but i had some problems with sending html-code.
i don't understand how i escape the control characters, i trying with
replace, but i will not work.

best regards


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to