Avalados por :

Cómo usar $.ajax para realizar peticiones HTTP de forma efectiva y segura

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 5 Vistas
0
Loading...
In general all requests can be done with the $.ajax function.

$.ajax can specify all HTTP Methods, send data to any URL wanted and realize success and error callbacks. $.get and $.post could be convenient.

In principle, you specify the HTTP method in the type attribute.
$.ajax({
  url: "https://YOUR_SYSTEM/sap/byd/odata/cust/v1/your_service/Collection..",
  type: 'GET', /* or POST or DELETE or PUT or PATCH or MERGE */
  datatype: 'json',
  data: { amount: '12.34' },
  success: function(oResult) { /* do something */ }
  error: function(oResult) { /* do something */ }
});

However, only GET and POST are perfectly supported. Other methods might be not supported by the server or client or are blocked by some firewall.

For best compatibility, create POST requests and set the header x-http-method to the wanted method with the headers attribute
$.ajax({
  url: "https://YOUR_SYSTEM/sap/byd/odata/cust/v1/your_service/Collection..",
  type: 'POST', 
  headers: { 'x-http-method': 'MERGE' /* or PUT or PATCH or DELETE */ },
  datatype: 'json',
  data: { amount: '12.34' },
  success: function(oResult) { /* do something */ }
  error: function(oResult) { /* do something */ }
});

Create


To create an instance, you execute a post request to the collection of the topmost node and pass the data. The callback is called with the created node.

The data
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

Sin respuestas

No hay respuestas para mostrar No hay respuestas para mostrar Se el primero en responder

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?