0

I can't echo value from ajax post. I don't know why. But when I same value put into

mysql_query("SELECT INTO something VALUES('$kategorija')"); <-- THIS WORK

but, echo $kategorija doesn't work

PHP FILE :

// pronadji-oglas.php

<?php
include_once('connect.php');
session_start();

$kategorija   = mysql_real_escape_string($_POST["kategorije"]);
$podkategorija= mysql_real_escape_string($_POST["podkat"]);

echo $kategorija;
?>

JS FILE :

// filter.js

$(function() {
$("#pronadji-oglas").click(function() {

    var kategorija = $("#kategorije").val();
    var podkategorija = $("#pod-kat").val();


    $.post("includes/pronadji-oglas.php", 
            {   kategorije: kategorija, 
                podkat: podkategorija
            },
            function(info) {
        });

    alert(kategorija);

    $("#pronadji-form").submit(function() {
        return false;
    }); 
});
$("#pronadji-oglas").click(function() {
    $(".dasdas").load("includes/pronadji-oglas.php");
});
});

HTML FILE :

<script src="js/kategorije.js"></script>
<script src="js/filter.js"></script>
<div class="pronadji">
    <form id="pronadji-form" action="" method="POST">
        Kategorija : 
        <select id="kategorije" name="kategorije" required>
            <option value="0">----Odaberi----</option>
                <?php include_once('kategorije.php'); ?>
        </select><br>
        Podkategorija : 
        <select id="pod-kat" name="pod-kat">
            <option value="0">----Odaberi---</option>
        </select><br>
        Mesto/Grad : 
        <select id="mesto-grad" name="mesto-grad">
            <option value="0">----Odaberi----</option>
            <?php include_once('mesto.php');?>
        </select>
        <select id="vreme">
            <option value="1">Po najnovijem</option>
            <option value="2">Po najstarijem</option>
        </select>
        <input type="submit" id="pronadji-oglas" value="Pronadji" />
    </form>
</div>
<div class="dasdas">

</div>
scunliffe
  • 62,582
  • 25
  • 126
  • 161
Nebojsa Sapic
  • 9,285
  • 1
  • 22
  • 23
  • 2
    What do you mean it doesn't work, you're not doing anything with the returned data in that $.post function ? – adeneo Aug 03 '14 at 16:27
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Aug 03 '14 at 16:33
  • @adeneo I want to value $categorija show in div with class name "dasdas". On click i'm sending values to php and load php file in class "dasdas". And nothing happened. What am i doing wrong. Can you help me, please – Nebojsa Sapic Aug 03 '14 at 16:34
  • You've attached 2 listeners to the click of `#pronadji-oglas` one actually sending the correct data, the other sending nothing. Couple that with the fact the a `submit` will reload the page if you don't do a `event.preventDefault()` and there's your problems. – Rob Schmuecker Aug 03 '14 at 16:37
  • @Quentin , thanks, i appreciate your answer, but for me now problem is to echo value – Nebojsa Sapic Aug 03 '14 at 16:39
  • @Quentin, my question is why this value work for mysql_query but not working for echo, i don't understand – Nebojsa Sapic Aug 03 '14 at 16:55
  • @shapic94 - see the duplicate question. It it working for echo, you just aren't looking at the result. – Quentin Aug 03 '14 at 17:46

0 Answers0