FooKelvin Posted August 26, 2015 Share Posted August 26, 2015 Hi i have stuck with the ajax return success. Firstly let me explain what i going to do. i have a input form, the form have 3 field text. 1) start Date 2) end Date 3) quarter the "quarter" field is a drop down list. i have a database to store the date of period of Q1,Q2,Q3,Q4. so i want to have, when a user select a drop down, the date will return the Q1 Period. For now, i'am able to return the result like this: [{"qstartDate":"11/1/2014","qendDate":"1/31/2014"}] But, when i wanted to return the date into my form, it fail. So, Here is my Code $("#slc-quarter").change(function () { var quarter = $(this).val(); $.ajax({ url: "searchQuarterDetails.asp?term=" + quarter, success: function (data) { var a = qstartDate; alert(a) } //$("#qstartDate").val(ui.item.qstartDate); //$("#qendDate").val(ui.item.qendDate); }) }) The result that i get from this code after i change the drop down menu is: [object htmlinputelement] Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/ Share on other sites More sharing options...
requinix Posted August 26, 2015 Share Posted August 26, 2015 The dates are stored in data, which is actually an array of dates so I don't know what you'd want to do if it returns more than one set of dates (if that's possible). data[0].qstartDate data[0].qendDate Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519682 Share on other sites More sharing options...
FooKelvin Posted August 27, 2015 Author Share Posted August 27, 2015 (edited) Hi requinix, i have two pages. select.asp and source.asp select.asp contain of 3 field. on of the field is drop down list. so, when user select the drop down, it trigger ajax "url: "source.asp?term=" + quarter". so the page of source.asp?term="+quarter" display: [{qstartDate: "2/1/2015", qendDate: "4/30/2015", label: "Q2"} 0: {qstartDate: "2/1/2015", qendDate: "4/30/2015", label: "Q2"} label: "Q2" qendDate: "4/30/2015" qstartDate: "2/1/2015" I need to take the "qendDate" value and "qstartDate" value. Edited August 27, 2015 by FooKelvin Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519708 Share on other sites More sharing options...
scootstah Posted August 27, 2015 Share Posted August 27, 2015 So something like this then? $("#slc-quarter").change(function () { var quarter = $(this).val(); $.ajax({ url: "searchQuarterDetails.asp?term=" + quarter, success: function (data) { $("#qstartDate").val(data[0].qstartDate); $("#qendDate").val(data[0].qendDate); } }) }) Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519709 Share on other sites More sharing options...
FooKelvin Posted August 27, 2015 Author Share Posted August 27, 2015 Hi scootstah, i tried but nothing appear in #qstartDate value. i try to change to console for more details. like this, success: function (data) { a = (data[0].qstartDate); console.log(a) $("#qendDate").val(data[0].qendDate); } the console.log return "undefined" Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519710 Share on other sites More sharing options...
requinix Posted August 27, 2015 Share Posted August 27, 2015 Exactly what does console.log(data);show? Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519722 Share on other sites More sharing options...
FooKelvin Posted August 27, 2015 Author Share Posted August 27, 2015 this console.log shows: [{"qstartDate":"2/1/2015","qendDate":"4/30/2015","label":"Q2"}] Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519724 Share on other sites More sharing options...
scootstah Posted August 27, 2015 Share Posted August 27, 2015 Try: $("#slc-quarter").change(function () { var quarter = $(this).val(); $.ajax({ url: "searchQuarterDetails.asp?term=" + quarter, dataType: 'json', success: function (data) { $("#qstartDate").val(data[0].qstartDate); $("#qendDate").val(data[0].qendDate); } }) }) 1 Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519739 Share on other sites More sharing options...
FooKelvin Posted August 27, 2015 Author Share Posted August 27, 2015 Hi scootstah, It's working. Thank You. Thanks everyone =) Quote Link to comment https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.