Commit 720dc1ca authored by Thimo Kraemer's avatar Thimo Kraemer

Add server action to endpoint url if protocol==url-encoded

parent 228ab049
......@@ -73,14 +73,13 @@ Some KSS in a file named *ajax.kss*:
protocol: url-encoded;
date-encoding: iso8601;
timeout: 5000;
endpoint: service.php;
}
#process:click,
#myform:submit {
evt-preventdefault: true;
kss-action-server: helloworld;
kss-action-server: service.php;
text: formVar("text");
counter: dataAttr("counter", true);
}
......@@ -93,26 +92,23 @@ Finally a PHP script named *service.php* that responds with some KSS commands:
require 'kss.php';
if ($_POST['kss_action'] == 'helloworld') {
$counter = $_POST['counter'] + 1;
$message = 'Hello '.$_POST['text'].'! ('.$counter.')';
$counter = $_POST['counter'] + 1;
$message = 'Hello '.$_POST['text'].'! ('.$counter.')';
$kss = new KSSResponse();
$kss = new KSSResponse();
$kss->replaceInnerHTML('#result', array(
'html'=>$message,
));
$kss->replaceInnerHTML('#result', array(
'html'=>$message,
));
$kss->setDataAttr('#myform', array(
'name'=>'counter',
'value'=>$counter,
));
$kss->setDataAttr('#myform', array(
'name'=>'counter',
'value'=>$counter,
));
$kss->focus('#text');
$kss->focus('#text');
$kss->send();
}
$kss->send();
?>
```
......
/*
* KSS-RPC v0.1-beta
* KSS-RPC v0.2-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
......@@ -61,7 +61,7 @@
******************************************************************************************/
var kss = {
version: '0.1-beta',
version: '0.2-beta',
_initialized: false,
_ruleSheets: {},
_eventBinders: {},
......@@ -1027,10 +1027,14 @@ kss.RPC.prototype.invoke = function(method, params,
}
var postData, headers;
var url = this._endpoint;
// Prepare the URL-ENCODED request
if (this._protocol == 'url-encoded') {
if (url && url.substr(-1) != '/') {
url += '/';
}
url += method;
postData = params || {};
postData.kss_action = method;
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
......@@ -1062,7 +1066,6 @@ kss.RPC.prototype.invoke = function(method, params,
}
// Prevent caching
var url = this._endpoint;
url += (url.indexOf('?') < 0) ? '?' : '&';
url += '_ts=' + new Date().getTime();
......@@ -2928,4 +2931,4 @@ kss._loadAnimationLib = function () {
kss.registerActionProvider('scroll', kss.scroll);
return lib;
};
\ No newline at end of file
};
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment