문제

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.

도움이 되었습니까?

해결책

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()
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top