skip to Main Content

I don’t know anything about ajax but i need solution.I would appreciate it if someone knowledgeable could help.I’m trying call php page by selection.Everything working well but except last result.This is uncertain number selection field.Its can be 3-4 selection fields or 10 selection fields with options.Page working by oneself but i can’t show that result in target page using ajax.I should post catid and get the result of get-values.php inside of .Someone can help me ?

I’m trying the code below with .load() and .html() but its not working.

function GetCatVal(val) {
    $.ajax({
        type: "POST",
        url: "./php/get-values.php",
        data:'catid='+val,
        success: function(data){
              
             HELLPPPPPP  sounds are getting louder from this area

    });
}

2

Answers


  1. Chosen as BEST ANSWER

    Actually problem is only select> tag.Code page working by oneself but i cant show result inside of div> tag.

    <select name="kat2" id="kat2-list" onChange="GetCatVal(this.value);">
                <option>Select Category</option>
            </select>
    
    
          <div id="katvallist"> </div>
    

    php file

      ...............
    $total2 = $response2->categoryProductAttributeList->categoryProductAttribute->count();
    curl_close($curl);
    
    
    for($i=0; $i<$total2; $i++) { 
    ..................
    echo "<label value=".$attid.">".$response2->categoryProductAttributeList->categoryProductAttribute[$i]->name."</label>";
    echo "<select>";
    

    -----------------Codes for Collecting Data from API------------------

    ---After to other selections i should show category attribute names and values.First loop for gather attribute names.This loop creating tags.Inside of this loop i have secondary loop for gather attribute values.Below echo giving that result to me as fine.-----

    echo "<option value=".$attlistid.">".$attlistname."</option>";
    

    script

    function GetCatVal(val) {
        $.ajax({
            type: "POST",
        url: "./php/get-values.php",
        data:'catid='+val,
    
        success: function(data){
            $("#katvallist").html(data);
    
        }
    });
    }
    

    If i try change some php code for show results inside of select tag its working fine.I can show result to select id="katvallist"> with only creating options> in php codes. but i cant show any data inside of div id="katvallist"> tag.


  2. would be nice to get more information where your code fails: in PHP or in ajax, do your get data in PHP or don’t even reach PHP code. Did you checked are you getting your 'catid='+val value in PHP code? I would recommend console.log(data) in success function.

    • var_dump($_POST);
    • F12 -> network -> find your get-values.php

    Also i would suggest:

    var param = "catid"+val

    data: {catid: param}
    Then in PHP you will get $_POST['catid']

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search