removed default dataType=json
This commit is contained in:
@ -4,6 +4,7 @@ X-editable changelog
|
|||||||
|
|
||||||
Version 1.2.1 wip
|
Version 1.2.1 wip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
[enh] removed default dataType='json' for submit request. Use 'ajaxOptions' to specify dataType if needed (vitalets)
|
||||||
[enh] select: do not show 'sourceError' in element during autotext execution (vitalets)
|
[enh] select: do not show 'sourceError' in element during autotext execution (vitalets)
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,8 +273,7 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
|
|||||||
return $.ajax($.extend({
|
return $.ajax($.extend({
|
||||||
url : this.options.url,
|
url : this.options.url,
|
||||||
data : params,
|
data : params,
|
||||||
type : 'post',
|
type : 'POST'
|
||||||
dataType: 'json'
|
|
||||||
}, this.options.ajaxOptions));
|
}, this.options.ajaxOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,12 +295,12 @@ $(function () {
|
|||||||
expect(4);
|
expect(4);
|
||||||
|
|
||||||
//clear cache
|
//clear cache
|
||||||
$(document).removeData('groups.php-name1');
|
$(document).removeData('groups-cache-sim.php-name1');
|
||||||
|
|
||||||
var req = 0;
|
var req = 0;
|
||||||
$.mockjax({
|
$.mockjax({
|
||||||
url: 'groups-cache-sim.php',
|
url: 'groups-cache-sim.php',
|
||||||
responseTime: 200,
|
responseTime: 50,
|
||||||
response: function() {
|
response: function() {
|
||||||
req++;
|
req++;
|
||||||
this.responseText = groups;
|
this.responseText = groups;
|
||||||
@ -312,7 +312,6 @@ $(function () {
|
|||||||
e2 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="3" data-url="post.php" data-source="groups-cache-sim.php"></a>').appendTo(fx).editable();
|
e2 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="3" data-url="post.php" data-source="groups-cache-sim.php"></a>').appendTo(fx).editable();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
||||||
equal(req, 1, 'one request');
|
equal(req, 1, 'one request');
|
||||||
equal(e.text(), groups[1], 'text1 correct');
|
equal(e.text(), groups[1], 'text1 correct');
|
||||||
equal(e1.text(), groups[2], 'text2 correct');
|
equal(e1.text(), groups[2], 'text2 correct');
|
||||||
@ -330,7 +329,7 @@ $(function () {
|
|||||||
expect(4);
|
expect(4);
|
||||||
|
|
||||||
//clear cache
|
//clear cache
|
||||||
$(document).removeData('groups.php-name1');
|
$(document).removeData('groups-cache-sim-err.php-name1');
|
||||||
|
|
||||||
var req = 0;
|
var req = 0;
|
||||||
$.mockjax({
|
$.mockjax({
|
||||||
@ -342,17 +341,16 @@ $(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var e = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="1" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">35</a>').appendTo(fx).editable(),
|
var e = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="1" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">11</a>').appendTo(fx).editable(),
|
||||||
e1 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="2" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">35</a>').appendTo(fx).editable(),
|
e1 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="2" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">22</a>').appendTo(fx).editable(),
|
||||||
e2 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="3" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">6456</a>').appendTo(fx).editable(),
|
e2 = $('<a href="#" data-type="select" data-pk="1" data-name="name1" data-value="3" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php"></a>').appendTo(fx).editable();
|
||||||
errText = $.fn.editabletypes.select.defaults.sourceError;
|
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
||||||
equal(req, 1, 'one request');
|
equal(req, 1, 'one request');
|
||||||
equal(e.text(), errText, 'text1 correct');
|
equal(e.text(), '11', 'text1 correct');
|
||||||
equal(e1.text(), errText, 'text2 correct');
|
equal(e1.text(), '22', 'text2 correct');
|
||||||
equal(e2.text(), errText, 'text3 correct');
|
equal(e2.text(), $.fn.editable.defaults.emptytext, 'text3 correct');
|
||||||
|
|
||||||
e.remove();
|
e.remove();
|
||||||
e1.remove();
|
e1.remove();
|
||||||
|
@ -218,6 +218,9 @@ $(function () {
|
|||||||
params: {
|
params: {
|
||||||
q: 2
|
q: 2
|
||||||
},
|
},
|
||||||
|
ajaxOptions: {
|
||||||
|
dataType: 'json'
|
||||||
|
},
|
||||||
success: function(resp) {
|
success: function(resp) {
|
||||||
equal(resp.dataType, 'json', 'dataType ok');
|
equal(resp.dataType, 'json', 'dataType ok');
|
||||||
equal(resp.data.pk, 1, 'pk ok');
|
equal(resp.data.pk, 1, 'pk ok');
|
||||||
@ -243,26 +246,31 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("params as function", function () {
|
asyncTest("params as function", function () {
|
||||||
var e = $('<a href="#" data-pk="1" data-url="post-resp.php">abc</a>').appendTo(fx).editable({
|
var e = $('<a href="#" data-pk="1" data-url="post-params-func.php">abc</a>').appendTo(fx).editable({
|
||||||
name: 'username',
|
name: 'username',
|
||||||
params: function(params) {
|
params: function(params) {
|
||||||
ok(this === e[0], 'scope is ok');
|
ok(this === e[0], 'scope is ok');
|
||||||
equal(params.pk, 1, 'params in func already have values (pk)');
|
equal(params.pk, 1, 'params in func already have values (pk)');
|
||||||
return { q: 2, pk: 3 };
|
return { q: 2, pk: 3 };
|
||||||
},
|
},
|
||||||
success: function(resp) {
|
|
||||||
equal(resp.dataType, 'json', 'dataType ok');
|
|
||||||
equal(resp.data.pk, 3, 'pk ok');
|
|
||||||
equal(resp.data.name, 'username', 'name ok');
|
|
||||||
equal(resp.data.value, newText, 'value ok');
|
|
||||||
equal(resp.data.q, 2, 'additional params ok');
|
|
||||||
},
|
|
||||||
ajaxOptions: {
|
ajaxOptions: {
|
||||||
headers: {"myHeader": "123"}
|
headers: {"myHeader": "123"}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
newText = 'cd<e>;"'
|
newText = 'cd<e>;"'
|
||||||
|
|
||||||
|
$.mockjax({
|
||||||
|
url: 'post-params-func.php',
|
||||||
|
response: function(settings) {
|
||||||
|
equal(settings.dataType, undefined, 'dataType undefined (correct)');
|
||||||
|
equal(settings.data.pk, 3, 'pk ok');
|
||||||
|
equal(settings.data.name, 'username', 'name ok');
|
||||||
|
equal(settings.data.value, newText, 'value ok');
|
||||||
|
equal(settings.data.q, 2, 'additional params ok');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
e.click()
|
e.click()
|
||||||
var p = tip(e);
|
var p = tip(e);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user