开发者

Updating a select box via AJAX

开发者 https://www.devze.com 2023-02-21 22:48 出处:网络
When I trying to update the whole select box via AJAX, only works first time. In the php side, always send the same info, the option fields one time are disabled and other time selected.

When I trying to update the whole select box via AJAX, only works first time. In the php side, always send the same info, the option fields one time are disabled and other time selected.

Is there some problem when replacing the whole select box?.

Here is the JS code.

$(document).ready(function(){
$("se开发者_如何学运维lect").change(function () {

        tid=location.href.replace(/^.*\/|\.[^.]*$/g, '');       
        colores=$("#colores option:selected").val();
        tallas=$("#tallas option:selected").val();
        marcas=$("#marcas option:selected").val();
        genero=$("#genero option:selected").val();
        $.get("/ajax/getdata/" + tid + ";" + colores + ";" + tallas + ";" + marcas + ";" + genero, function(data){
                    // Asignamos las nuevas opciones para el combo2
        $(".content").html(data);

        });
    })
});


Why do you use ";" as separator for your values ? You should use the "data" parameter instead :

var oData = {
    'colores': colores,
    'tallas': tallas,
    'marcas': marcas,
    'genero': genero
}
$.get("/ajax/getdata/", oData, function (data) {
    // Asignamos las nuevas opciones para el combo2
    $(".content").html(data);
});

And use the $_GET[] in your PHP page :

<?php
$colores = $_GET['colores'];
$tallas = $_GET['tallas'];
$marcas = $_GET['marcas'];
$genero = $_GET['genero'];

// Do what you need to do with this
?>

But if your PHP always return the same value and shouldn't, it's probably a cache problem with your browser : since you do a request to the same url, your browser once do the call, but then keep the previous returned data for every next calls (in order to reduce bandwidth use). In order to avoid this problem, you can add a parameter that always change (like a timestamp).

Tell me if this answer is good for you or I'll adapt it regarding to your indications.

0

精彩评论

暂无评论...
验证码 换一张
取 消