This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hell no, what a title :) What i have is a Javascript AJAX request inside an onClick button and i want to pass a variable to the requesting function. This is my javascript AJAX code:
$.request('onRating, { data: {jsAnswer: 55}, success: function() { console.log('Data!'); } })
I now would love to pass the jsAnswer value to this function:
function onRating(){ Db::table('company_profiles_rating')->insert( ['user_id' => 44, 'question_id' => 0, 'answer_value' => jsAnswer] ); }
But this does not work. I also tried to insier tthe jsAnswer inside the brackets of the function but then i get an error. What am i doing wrong?
Perhaps I'm reading this incorrectly because I'm lacking my morning coffee, but this appears to be a scope issue you are having. jsAnswer only exists in the data object within that specific request. If you want to use it elsewhere, it needs to exist elsewhere. Where is that value coming from? If it is a text field in your form then you can easily just grab it's value and set it to a javascript variable BEFORE your request code, but then it would also be available to use inside your function that way. However, if I'm missing something you are free to ignore me completely. Cheers.
1-2 of 2