remove datatype=json from submit api method
This commit is contained in:
@ -449,22 +449,13 @@ Makes editable any HTML element on the page. Applied as jQuery method.
|
|||||||
$.ajax($.extend({
|
$.ajax($.extend({
|
||||||
url: config.url,
|
url: config.url,
|
||||||
data: values,
|
data: values,
|
||||||
type: 'POST',
|
type: 'POST'
|
||||||
dataType: 'json'
|
|
||||||
}, config.ajaxOptions))
|
}, config.ajaxOptions))
|
||||||
.success(function(response) {
|
.success(function(response) {
|
||||||
//successful response
|
//successful response
|
||||||
if(typeof response === 'object' && response.id) {
|
if(typeof config.success === 'function') {
|
||||||
$elems.editable('option', 'pk', response.id);
|
config.success.apply($elems, arguments);
|
||||||
$elems.removeClass('editable-unsaved');
|
}
|
||||||
if(typeof config.success === 'function') {
|
|
||||||
config.success.apply($elems, arguments);
|
|
||||||
}
|
|
||||||
} else { //server-side validation error
|
|
||||||
if(typeof config.error === 'function') {
|
|
||||||
config.error.apply($elems, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.error(function(){ //ajax error
|
.error(function(){ //ajax error
|
||||||
if(typeof config.error === 'function') {
|
if(typeof config.error === 'function') {
|
||||||
|
@ -212,7 +212,7 @@ $(function () {
|
|||||||
equal(e.text(), 'abcd', 'text set correctly (by object)');
|
equal(e.text(), 'abcd', 'text set correctly (by object)');
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("'submit' method: client and server validation", function () {
|
asyncTest("'submit' method: client and server validation errors", function () {
|
||||||
var ev1 = 'ev1',
|
var ev1 = 'ev1',
|
||||||
ev2 = 'ev2',
|
ev2 = 'ev2',
|
||||||
e1v = 'e1v',
|
e1v = 'e1v',
|
||||||
@ -236,15 +236,22 @@ $(function () {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.mockjax({
|
||||||
|
url: 'new.php',
|
||||||
|
response: function(settings) {
|
||||||
|
ok(false, 'should not submit to new.php');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(fx).find('.new').editable('submit', {
|
$(fx).find('.new').editable('submit', {
|
||||||
url: 'new.php',
|
url: 'new.php',
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
ok(data.errors, 'errors defined');
|
ok(data.errors, 'errors defined');
|
||||||
equal(data.errors.text, 'invalid', 'client validation error ok');
|
equal(data.errors.text, 'invalid', 'client validation error ok');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//change value to pass client side validation
|
//change value to pass client side validation
|
||||||
e.click();
|
e.click();
|
||||||
var p = tip(e);
|
var p = tip(e);
|
||||||
@ -261,15 +268,21 @@ $(function () {
|
|||||||
start();
|
start();
|
||||||
},
|
},
|
||||||
ajaxOptions: {
|
ajaxOptions: {
|
||||||
type: 'PUT'
|
type: 'PUT',
|
||||||
|
dataType: 'json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
e.remove();
|
||||||
|
e1.remove();
|
||||||
|
start();
|
||||||
|
}, timeout);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
asyncTest("'submit' method: server error", function () {
|
asyncTest("'submit' method: server error", function () {
|
||||||
expect(2);
|
|
||||||
var ev1 = 'ev1',
|
var ev1 = 'ev1',
|
||||||
e1v = 'e1v',
|
e1v = 'e1v',
|
||||||
e = $('<a href="#" class="new" data-type="text" data-url="post.php" data-name="text">'+ev1+'</a>').appendTo(fx).editable(),
|
e = $('<a href="#" class="new" data-type="text" data-url="post.php" data-name="text">'+ev1+'</a>').appendTo(fx).editable(),
|
||||||
@ -278,7 +291,10 @@ $(function () {
|
|||||||
$(fx).find('.new').editable('submit', {
|
$(fx).find('.new').editable('submit', {
|
||||||
url: 'error.php',
|
url: 'error.php',
|
||||||
error: function(data) {
|
error: function(data) {
|
||||||
ok(!data.errors, 'no client errors');
|
equal(this[0], $(fx).find('.new')[0], 'success context ok');
|
||||||
|
equal(this[1], $(fx).find('.new')[1], 'success context2 ok');
|
||||||
|
|
||||||
|
equal(data.status, 500, 'status 500 ok');
|
||||||
equal(data.responseText, 'customtext', 'server error ok');
|
equal(data.responseText, 'customtext', 'server error ok');
|
||||||
|
|
||||||
e.remove();
|
e.remove();
|
||||||
@ -290,7 +306,6 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest("'submit' method: success", function () {
|
asyncTest("'submit' method: success", function () {
|
||||||
expect(7);
|
|
||||||
var ev1 = 'ev1',
|
var ev1 = 'ev1',
|
||||||
e1v = 'e1v',
|
e1v = 'e1v',
|
||||||
pk = 123,
|
pk = 123,
|
||||||
@ -302,20 +317,16 @@ $(function () {
|
|||||||
response: function(settings) {
|
response: function(settings) {
|
||||||
equal(settings.data.text, ev1, 'first value ok');
|
equal(settings.data.text, ev1, 'first value ok');
|
||||||
equal(settings.data.text1, e1v, 'second value ok');
|
equal(settings.data.text1, e1v, 'second value ok');
|
||||||
this.responseText = {id: pk};
|
this.responseText = 'response-body';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(fx).find('.new').editable('submit', {
|
$(fx).find('.new').editable('submit', {
|
||||||
url: 'new-success.php',
|
url: 'new-success.php',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
equal(e.data('editable').options.pk, pk, 'pk1 ok');
|
equal(this[0], $(fx).find('.new')[0], 'success context ok');
|
||||||
ok(!e.hasClass('editable-changed'), 'no "editable-changed" class');
|
equal(this[1], $(fx).find('.new')[1], 'success context2 ok');
|
||||||
|
equal(data, 'response-body', 'response body ok');
|
||||||
equal(e1.data('editable').options.pk, pk, 'pk2 ok');
|
|
||||||
ok(!e1.hasClass('editable-changed'), 'no "editable-changed" class');
|
|
||||||
|
|
||||||
equal(data.id, pk, 'server result id ok');
|
|
||||||
|
|
||||||
e.remove();
|
e.remove();
|
||||||
e1.remove();
|
e1.remove();
|
||||||
|
Reference in New Issue
Block a user