开发者

jQuery + Coldfusion, isNumeric not validating

This is the jQuery, both the game_id and the $(this).val() are integers

    /* AJAX call: save to DB input name=#game_id# v开发者_运维技巧alue=#game_rating */
    $.post("game_rating_submit.cfm", {
        id: game_id,
        rating: $(this).val()
     }, 
     function(data) {
        alert('data: ' + data);
    });

This is the coldfusion part that's failing:

<cfif NOT IsNumeric("form.rating")>
    <cfset variables.error = 'Invalid rating value #form.rating#.' >
</cfif>
<cfoutput>#variables.error#</cfoutput>

For some reason form.rating is not numeric?


When quoted "form.rating" is the string "form.rating", if you want the value try...

 <cfif NOT IsNumeric(form.rating)>
     <cfset variables.error = 'Invalid rating value #form.rating#.' >
 </cfif>
 <cfoutput>#variables.error#</cfoutput>


I think rating: $(this).val() is referring to the wrong DOM element. Pull that reference outside the .post method, like so.

var rating = $('#my_rating_elem').val();
$.post('game_rating_submit.cfm', { id: game_id, rating: rating}) ...

Or make sure that $(this) is referring to the object you expect by assigning it to another local variable

var klass = $(this); $.post('game_rating_submit.cfm', { id: game_id, rating: klass.val()}) ...

This is necessary because in the context of the .post() method the $(this) is NOT referring to the object you were expecting (which is the $(this) outside the .post())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜