PARAMETERS GET shipping

0

I have this code js that receives two parameters day name what I want is to get them to another page called mad in which I send direct parameters to a service called days so that Bring me the results and paint them on a div called sample

$("#envia").click(function () {
              var datos={
                         dia: $("#nivel").val(),
                         nombre: $("#curp").val()
                        }; 

          $.ajax({
        url: "mad.php",
        type: "GET",
        dataType: "json",
        data: datos,

        success: function (result) {
            $("#muestra").html(result);
        }
    })
});

* this is the js that resides the variables but does not do anything I do not know if I am receiving them well does not mark me any error simply does not show me anything *

$(document).ready(function () {

var datos={
                         dia: $("#dia").val(),
                         nombre: $("#nombre").val()
                        }; 

            $.ajax({
                    url: 'wservice/dias.php',
                    type: 'GET',
                    dataType: 'json',
                    data: datos,
                })
            .done(function (respuesta) {

                  console.log("dia:"+respuesta.dia);
                  console.log("Nombre:"+respuesta.Nombre);
                  console.log("a:"+respuesta.a);
)}
)};
    
asked by JV93 06.11.2018 в 20:51
source

1 answer

0

Hello, it was not very clear to me if the data you receive in "mad.php" you save it in an input and then recover it and send it to "dias.php" if so, your code should work correctly. If you want to obtain the fields directly from the url you could do it with the following function

$.urlParam = function(name){
  var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
  if (results==null){
     return null;
  }
  else{
   return decodeURI(results[1]) || 0;
  }
}

Basically it works it looks for in the url the parameters by the name of the same ones. The function is not author's credits to the author. Source Code

  • Solution with your example code

$(document).ready(function(){
var datos = {
	dia: $.urlParam('nombre'), //Aqui Utilizas la funcion ($.urlParam) para obtener los campos desde la URL
	nombre: $.urlParam('dia')
	}; 
console.log(datos);
$.ajax({
    		url: "wservice/dias.php",
    		type: "GET",
    		dataType: "json",
    		data: datos,
	})
.done(function (respuesta) {
	console.log("dia:"+respuesta.dia);
	console.log("Nombre:"+respuesta.Nombre);
	console.log("a:"+respuesta.a);
})
});
    
answered by 07.11.2018 в 01:00