cikcak Posted January 27, 2015 Share Posted January 27, 2015 (edited) Hey, Briefly, I would like to get value of select input and save it to my module php file. I need to save it to use it in other page. Mymodule.tpl: <select id="gr"> <option selected="selected">-</option> <option value="2">two</option> <option value="4">four</option> </select> js/mymodule.js content: $( document ).ready(function() { $('#gr').on('change', fixValue); }); function fixValue() { which = $('select#gr option:selected').val(); $("#rez").text(gr); $.ajax({ type: 'POST', url: baseDir + 'modules/mymodule/ajax.php', data: 'method=myMethod&id_data=' + $('select#gr option:selected').val(), dataType: 'json', success: function(json) { alert("ok"); } }); } So this ajax.php file content: <?php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); switch (Tools::getValue('method')) { case 'myMethod' : die( Tools::jsonEncode( array('result'=>'my_value')); break; default: exit; } exit; ?> First of all, I don`t see alert so why it not works? And second question, how should I use that value in mymodule.php?Thanks for any help! Edited January 27, 2015 by cikcak (see edit history) Link to comment Share on other sites More sharing options...
jsmit2 Posted January 27, 2015 Share Posted January 27, 2015 $('#gr').change(function(){ //Call ajax here }); You are not calling the function correctly Link to comment Share on other sites More sharing options...
cikcak Posted January 27, 2015 Author Share Posted January 27, 2015 $('#gr').change(function(){ //Call ajax here }); You are not calling the function correctly Okey, thanks, but I can`t find any information how to get value in my module php. Should I use controller or what? Ill try this! Thanks! Link to comment Share on other sites More sharing options...
cristic Posted January 27, 2015 Share Posted January 27, 2015 If you check Chrome's "Inspect element" - do you see one request fired for baseDir + 'modules/mymodule/ajax.php' when changing the selected option? If yes, what is the request status code? Link to comment Share on other sites More sharing options...
jsmit2 Posted January 27, 2015 Share Posted January 27, 2015 You must use your main php file. The one that defines your module. I dont know how to process it further Link to comment Share on other sites More sharing options...
vekia Posted January 27, 2015 Share Posted January 27, 2015 check browser console. ctrl+shift+j in chrome open "network" tab and see headers ($_POST values) of your ajax request does it push correct params? You must use your main php file. The one that defines your module. I dont know how to process it further you can use any other .php file inside in the module and there is no need to use it as a controller Link to comment Share on other sites More sharing options...
cikcak Posted January 27, 2015 Author Share Posted January 27, 2015 (edited) Vekia already answered. Nice! Ill try! Edited January 27, 2015 by cikcak (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now