Advertisement
Guest User

for my bro

a guest
Mar 26th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. var collection = new Backbone.Collection.extend({
  2. model: ItemModel,
  3. url: '/Items'
  4. })
  5.  
  6. collection.fetch({ data: { page: 1} });
  7.  
  8. collection.fetch({ data: { page: 1} });
  9.  
  10. collection.fetch({ data: $.param({ page: 1}) });
  11.  
  12. Backbone.sync = function(method, model, options) {
  13. var type = methodMap[method];
  14.  
  15. // Default JSON-request options.
  16. var params = _.extend({
  17. type: type,
  18. dataType: 'json',
  19. processData: false
  20. }, options);
  21.  
  22. // Ensure that we have a URL.
  23. if (!params.url) {
  24. params.url = getUrl(model) || urlError();
  25. }
  26.  
  27. // Ensure that we have the appropriate request data.
  28. if (!params.data && model && (method == 'create' || method == 'update')) {
  29. params.contentType = 'application/json';
  30. params.data = JSON.stringify(model.toJSON());
  31. }
  32.  
  33. // For older servers, emulate JSON by encoding the request into an HTML-form.
  34. if (Backbone.emulateJSON) {
  35. params.contentType = 'application/x-www-form-urlencoded';
  36. params.processData = true;
  37. params.data = params.data ? {model : params.data} : {};
  38. }
  39.  
  40. // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
  41. // And an `X-HTTP-Method-Override` header.
  42. if (Backbone.emulateHTTP) {
  43. if (type === 'PUT' || type === 'DELETE') {
  44. if (Backbone.emulateJSON) params.data._method = type;
  45. params.type = 'POST';
  46. params.beforeSend = function(xhr) {
  47. xhr.setRequestHeader('X-HTTP-Method-Override', type);
  48. };
  49. }
  50. }
  51.  
  52. // Make the request.
  53. return $.ajax(params);
  54. };
  55.  
  56. collection.fetch({
  57. data: { page: 1},
  58. processData:true
  59. );
  60.  
  61. if (params.type !== 'GET' && ! Backbone.emulateJSON) {
  62. params.processData = false;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement