Ya no tienes que indagar más por todo internet porque llegaste al sitio perfecto, poseemos la respuesta que buscas pero sin complicarte.
Ejemplo 1: llamada de publicación de datos ajax en javascript
$.ajax(url:'ajaxfile.php',type:'post',data:name:'yogesh',salary:35000,email:'[email protected]',success:function(response));
Ejemplo 2: como enviar datos usando ajax
$.ajax(url:"/something",// the url we want to send and get data fromtype:"GET",// type of the data we send (POST/GET)data:p1:"This is our data",// the data we want to sendsuccess:function(data)// when successfully sent data and returned// do something with the returned data
console.log(data);).done(function()// this part will run when we send and return successfully
console.log("Success.");).fail(function()// this part will run when an error occurres
console.log("An error has occurred.");).always(function()// this part will always run no matter what
console.log("Complete."););
Ejemplo 3: publicación de jquery ajax
// Variable to hold requestvar request;// Bind to the submit event of our form
$("#foo").submit(function(event)// Prevent default posting of form - put here to work in case of errors
event.preventDefault();// Abort any pending requestif(request)
request.abort();// setup some local variablesvar$form= $(this);// Let's select and cache all the fieldsvar$inputs=$form.find("input, select, button, textarea");// Serialize the data in the formvar serializedData =$form.serialize();// Let's disable the inputs for the duration of the Ajax request.// Note: we disable elements AFTER the form data has been serialized.// Disabled form elements will not be serialized.$inputs.prop("disabled",true);// Fire off the request to /form.php
request = $.ajax(url:"/form.php",type:"post",data: serializedData
);// Callback handler that will be called on success
request.done(function(response, textStatus, jqXHR)// Log a message to the console
console.log("Hooray, it worked!"););// Callback handler that will be called on failure
request.fail(function(jqXHR, textStatus, errorThrown)// Log the error to the console
console.error("The following error occurred: "+
textStatus, errorThrown
););// Callback handler that will be called regardless// if the request failed or succeeded
request.always(function()// Reenable the inputs$inputs.prop("disabled",false);););
Aquí puedes ver las reseñas y valoraciones de los lectores
Puedes confirmar nuestra misión ejecutando un comentario o puntuándolo te damos las gracias.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)