1

Myproblem is when I click my first selectbox, after there is a value, it will trigger the second selectbox. I implement it in Ajax, but successfully render ,but my other textfield value is gone. How could I just render a specific part of the responde html(success ajax call)?

$(document).ready(function(){ 

    if ($('#product_category').val() == 'Choose Category')
        document.getElementById('product_subcategory').disabled = true;

    $('#product_category').change(function () {   
        if ($('#product_category').val() == 'Choose Category')
            document.getElementById('product_subcategory').disabled = true;
        else
            document.getElementById('product_subcategory').disabled = false;


        data = $('#product_category').val();
        //alert(data);

        var param = 'category_name=' + data;
        $.ajax({
          url: MYURL,
          data: param,
          success: function(result) {
            alert('Choose product subcategory');
            alert(param);
            $('body').html('');
            $('body').html(result);
          }
        });
       //   window.location = MYURL?category_name="+data;
    });

    $('#product_subcategory').change(function () {    
        data = $('#product_subcategory').val();
     //     paramCategory = $(document).getUrlParam('category_name');
      //    alert(paramCategory);

        $.get(MYURL, function(data){
            alert("Data Loaded: " + data);
            });
        //window.location = MYURL?subcategory_name=" +  data;
    });

});

in my form, i use $_GET['category_name'] to get my value Ajax return value. I Debug in firebug, and it is successfully. I tried to render again the html, but my previous textarea's value and textfiel's value is gone since what i did is $('body').html(''); $('body').html(result);, So,how could I manage to get the success ajax return value, and use it in the PHP.

any confusion ,please tell me... Thank you for spending ur time.


Hmm, I'm using a div and show the Div when it was return success ajax call.

4

4 回答 4

1

问题就在这里,

$('body').html('');
$('body').html(result);

您正在空白整个身体并插入新结果。您必须将其更改为

$('#second_select_box_id').html(result);
于 2012-10-05T06:32:52.557 回答
1
$('body').html('');
$('body').html(result);

这是清空您的页面并在其中插入您的结果,我想您真正想要做的是用结果加载您的第二个下拉列表,因为您需要这样做

$("#product_subcategory").html(result);

当然,这将取决于您的 ajax 函数返回的结果是什么

于 2012-10-05T06:32:56.910 回答
0

你能试试这个吗

$(body).html('');
$(body).html(result);
于 2012-10-05T06:32:10.280 回答
0

你有两种方法可以做到这一点。

  1. 在返回 Ajax 调用的数据时添加来自 PhP 的文本

  2. 加载页面后将数据添加回文本框..

    数据 = $('#product_category').val(); //警报(数据);

    var param = 'category_name=' + 数据;$.ajax({ url: MYURL, data: param, success: function(result) { alert('选择产品子类别'); alert(param); $('body').html(''); $(' body').html(result); $('#product_category').val(data); } });

于 2012-10-05T06:38:28.240 回答