Frage

Here the Select /Combobox static value pass to controller using script is not working properly, the script alert is working.

Html code

<select id="propertyfor" onchange="onPropertyforChange();">
<option value="0">Select Property For</option>
<option value="SELL" id="1" th:value="${'SELL'}">SELL</option>
<option value="RENT" id="2" th:value="${'RENT'}">RENT</option>
</select>

script code

function onPropertyforChange() {
    alert("HI");
    $.ajax({
        type : 'POST',
        dataType : 'json',
        url : '/RealEstate/selectedPropertyfor.html',
        data : ({
            id : $('#propertyfor').val()
        })    
    });
}

the alert shows here but the controller println not working

Controller

@ResponseBody
@RequestMapping(value = ("/selectedPropertyfor.html"))
public void getpropertyFor(@RequestParam("propertyfor") int propertyfor) {
    System.out.println(propertyfor+"QQQQQQQQQQQQQ");
}

if you know about this please share answer here.

War es hilfreich?

Lösung

You are sending the value of the select with the property name of id, not propertyfor. Also, your data syntax is a little odd.

data: {
    propertyfor : $('#propertyfor').val()
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top