Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
Passing a variable to an Ajax call

I am using the code below to rotate and save an image stored on the server.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://beneposto.pl/jqueryrotate/js/jQueryRotateCompressed.js"></script>

<img src="uploads/101822973264163759893-1428320267361.jpeg" id="img"/>

<script> 
$(document).ready(function(){
var value = 0
    $("#img").rotate({ 
       bind: 
         { 
            click: function(){
                value +=90;
                $(this).rotate({ animateTo:value})
            }
         } 

    });


    $(document).on('click', '#img', function() {
                // alert("Hello");

                var idno = "test";
                $.ajax({
                         url: "saveimage.php",
                         dataType: "html",
                         type: 'POST',
                         data: "panelid="+idno, //variable with data
                         success: function(data){
                            // $(".test").html(data);
                                // alert(data);
                         }
                });
    });
});
</script>

saveimage.php

<?Php
$degrees = -90;  //change this to be whatever degree of rotation you want

header('Content-type: image/jpeg');

$filename = 'uploads/101822973264163759893-1428320267361.jpeg';  //this is the original file

$source = imagecreatefromjpeg($filename) or notfound();
$rotate = imagerotate($source,$degrees,0);

imagejpeg($rotate,$filename); //save the new image

imagedestroy($source); //free up the memory
imagedestroy($rotate);  //free up the memory

?>

I found this code here - http://www.codehaven.co.uk/rotate-and-save-an-image-using-php/.

This all works fine but I am trying to pass a PHP variable which holds the image path and name to the ajax call and have no idea on how to do this.

Can anyone help?

thanks,

John

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can pass the variable as URL parameters:

url: "saveimage.php?path=/folder/to/your/image/&image=image_name",

You can use urlencode to make sure all the special characters are pass through

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda