Sent data via GET and POST with Java Script

Asked

Viewed 66 times

-2

People see if anyone can help I have a variable called "ssid" where there is information that to send to a php file, someone can help me how to do?

function chamarSS(ssId ){
    if(ssId){
       console.log("SS: " + ssId);
    }
}  
<th style='text-align:center'><a href="javascript:;" id="ssId"  onclick="chamarSS('<?php echo $obj->SS; ?>');">DADOS</a></th> 

1 answer

0


Guy is not recommended you use Javascript for data transport, it is very explicit and is something very dangerous, if you are working with important data that can put at risk financial loss or even loss of something, I recommend using PHP much safer.

But so for you to do a GET You can use both getJSON(Jquery) AJAX(Jquery)

function recViaCep(){
  $.ajax({
    url: "https://viacep.com.br/ws/"+ $("#cep").val()+"/json/", 
    type: "GET",   
    dataType: 'json',
    success: function(response){
      dados = response;
      $('#logradouro').val(dados.logradouro.toUpperCase());
      $('#bairro').val(dados.bairro.toUpperCase());
      $('#cidade').val(dados.localidade.toUpperCase());
      $('#estado').val(dados.uf.toUpperCase());
      initMap();    
      $("#nomeRegristro").val($("#CNPJCPF").val() + " - " + $("#nomeAnalista").val())
    }
});

}

In this example I am requesting a JSON by AJAX, which for proper purposes will not put at risk my company, so see what you need to do!!

$.getJSON("demo_ajax_json.js", function(result){ $.each(result, function(i, field){ $("div").append(field + " "); }); });

Already here is an example of request by JSON

As I said, be careful with the post method, the JS will not leave your data safe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.