3
Hi, I’m not very good at javascript,ajax,jquery and json I’m still learning and remembering that I’ve researched a lot, but I couldn’t do what I want. The following is my project is in MVC with friendly url. On the page has a text box that validates the zip code and displays the freight values that I did with PHP, but I had to put two options with radio to choose the type of freight, I wanted the moment I clicked on the type of freight for example "Pac" or "sedex" he updated the page and sent this value to a PHP variable.
here the file load.js.
$(document).ready(function() {
$('#botao').click(function(){
$('#aguarde, #blanket').css('display','block');
});
$("input:radio").click(function() {
var cor = $(this).val();
var correio = cor;
$.post("lojavirtualpoo/carrinho<-não estou sabendo colocar isso aqui",
{
correio: correio
},function(){
console.log(correio);
});
});
});
this page is located in localhost/lojavirtualpoo/app/views/cart/Index.php, inside the page Index.php has these code to receive the value but does not receive localhost/lojavirtualpoo/app/views/cart/Index.php
$tipo_correio = $_POST["correio"];
var_dump($tipo_correio);
html code on the same page
<td>
<span class="tt1">Opção</span>
<?php if ($cep_destino != "") { ?>
<span class="tt2"><input type="radio" name="correio" value="pac"> 1</span>
<span class="tt2"><input type="radio" name="correio" value="sedex"> 2</span>
<?php } else { ?>
<span class="tt2">Nenhum resultado</span>
<?php } ?>
</td>
directly accessing the url
lojavirtualpoo/carrinho
works?– edson alves
works yes, on the console when I click one of the two options appears on the Pac or sedex console
– Carlos Renato
It may be that you are giving error. See in the network tab of devtools the response of the request
– edson alves
I checked the status is 200 as ok, I click on one of the options and the console appears normal, but the receive variable in php $type_mail does not receive the value...
– Carlos Renato
Notice: Undefined index: correio in C: wamp64 www lojavirtualpoo app views carrinho Index.php on line 2
– Carlos Renato
Already tried to put in the Ajax URL the absolute path:
http://localhost/lojavirtualpoo/app/views/carrinho/Index.php
?– Sam
Yes I have tested and it didn’t work, I’m studying to know where the error is, you want to leave it open? or better close? I’m sure if I devote a little more time to mastering these technologies I’ll know how to do what I want...
– Carlos Renato