Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions core-xhr.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,29 @@
}
return xhr;
},

toQueryString: function(params) {
var r = [];
for (var n in params) {
var v = params[n];
n = encodeURIComponent(n);
r.push(v == null ? n : (n + '=' + encodeURIComponent(v)));
if(v == null){
r.push(n);
}else{
v = this.isString(v) ? v : JSON.stringify(v);
r.push(n + '=' + encodeURIComponent(v));
}
}
return r.join('&');
},

isString:function(str){
return str instanceof String ||
typeof str === 'string';
},
isBodyMethod: function(method) {
return this.bodyMethods[(method || '').toUpperCase()];
},

bodyMethods: {
POST: 1,
PUT: 1,
Expand All @@ -111,5 +119,5 @@
});

</script>

</polymer-element>
47 changes: 47 additions & 0 deletions tests/html/core-ajax-arrays.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-ajax</title>

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-ajax.html">

</head>
<body>

<core-ajax
id="arrays"
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"alt":"json","key1": ["a","b","c"]}'
handleAs="json"
auto>
</core-ajax>

<script>

document.addEventListener('polymer-ready', function() {

var arraysAjax = document.querySelector('core-ajax#arrays');
arraysAjax.addEventListener("core-response", function(event) {
chai.assert.isTrue(event.detail.response.feed.entry.length > 0);
chai.assert.equal(event.detail.xhr.responseURL, "http://gdata.youtube.com/feeds/api/videos/?alt=json&key1=" + encodeURIComponent(JSON.stringify(["a","b","c"])));
done();
});

});

</script>

</body>
</html>
44 changes: 44 additions & 0 deletions tests/html/core-ajax-complexe-object.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-ajax</title>

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-ajax.html">

</head>
<body>

<core-ajax
id="multi-level"
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"alt":"json","key1": {"key21":{"key211":"value211"}}}'
handleAs="json"
auto>
</core-ajax>
<script>

document.addEventListener('polymer-ready', function() {

var multiLevelAjax = document.querySelector('core-ajax#multi-level');
multiLevelAjax.addEventListener("core-response", function(event) {
chai.assert.equal(event.detail.xhr.responseURL, "http://gdata.youtube.com/feeds/api/videos/?alt=json&key1=" + encodeURIComponent(JSON.stringify({"key21":{"key211":"value211"}})));
done();
});
});

</script>

</body>
</html>
26 changes: 22 additions & 4 deletions tests/html/core-ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,38 @@
<body>

<core-ajax
id="simple"
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"alt":"json", "q":"chrome"}'
handleAs="json"
auto></core-ajax>
auto>
</core-ajax>
<!--
<core-ajax
id="arrays"
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"key1": ["a","b","c"]}'
handleAs="json"
auto>
</core-ajax> -->

<script>

document.addEventListener('polymer-ready', function() {
var assert = chai.assert;
var ajax = document.querySelector('core-ajax');
ajax.addEventListener("core-response", function(event) {
assert.isTrue(event.detail.response.feed.entry.length > 0);
var simpleAjax = document.querySelector('core-ajax#simple');
simpleAjax.addEventListener("core-response", function(event) {
chai.assert.isTrue(event.detail.response.feed.entry.length > 0);
done();
});


// var arraysAjax = document.querySelector('core-ajax#arrays');
// arraysAjax.addEventListener("core-response", function(event) {
// assert.isTrue(event.detail.response.feed.entry.length > 0);
// done();
// });

});

</script>
Expand Down
4 changes: 3 additions & 1 deletion tests/js/htmltests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
htmlSuite('core-ajax', function() {
htmlTest('html/core-ajax.html');
});
htmlTest('html/core-ajax-complexe-object.html');
htmlTest('html/core-ajax-arrays.html');
});