Hi. I need help with this section of code.
What I want to do is; when I click (for example) a radio button 1, that button value display on the browser. I have a three radio buttons.
Here's my ajax query:
function updatepayment(this.value)()
var ajaxResponse = new Object();
$(document).ready(f开发者_JAVA百科unction () {
$('.rmr').click(function () {
var rbVal = $(this).val();
var myContent;
if (ajaxResponse[rbVal]) { //in cache
myContent = ajaxResponse[rbVal];
$("#contentcontainer").html(myContent);
}
else { // not in cache
var urlForAjaxCall = "include/function.php" + rbVal + ".html";
$.post(urlForAjaxCall, function (myContent) {
ajaxResponse[rbVal] = myContent;
$("#contentcontainer").html(myContent);
});
}
});
});
- Your cache check will always be false since you always re-declare ajaxResponse in the function. ajaxResponse should be declared globally.
- And you dont really need the post function (as your not posting any data) you could just use the .load function.
- You dont need a function to wrap the $(document).ready function
var ajaxResponse = new Object();
$(document).ready(function(){
$('.rmr').click(function (){ var rbVal = $(this).val(); var myContent; if (ajaxResponse[rbVal]) { //in cache $("#contentcontainer").html( ajaxResponse[rbVal] ); } else { // not in cache var urlForAjaxCall = "include/function.php" + rbVal + ".html"; $("#contentcontainer").load(urlForAjaxCall, function (myContent) { //Extra processing can be done here, like your cache ajaxResponse[rbVal] = myContent; }); }
});
});
EDIT: After seeing your comments on your OP You are trying to select the radio buttons by class name "rmr" but do not have it set on the tags you need:
<input class="rmr" type="radio" name="rmr" id="payment1" value="3" onclick="updatepayment(this.value)" /> <br>
<input class="rmr" type="radio" name="rmr" id="payment2" value="5.5" onclick="updatepayment(this.value)" /><br>
<input class="rmr" type="radio" name="rmr" id="payment4" value="10" onclick="updatepayment(this.value)" /><br>
or you could use
$("input[name=rmr]")
to select them by their input name attribute
精彩评论