i need to make ajax call on option change of for first select value and 
display second select option based on the value select from first select 
option and update second select option with json value sent from server.


.jade file

form.form-horizontal(id="createDealForm", accept-charset="UTF-8", 
action="#", method="post" enctype="multipart/form-data")
      select#selectsourcecity(name="sourcecity", required="required")
        each sourceCity in sourceCities
          option(value=sourceCity.cityId) #{sourceCity.cityName}
    h4 To
     #selectdestinationcity
       
      
ajax script

$('#selectsourcecity').change(function() {
    var data = "";
    console.log('value ' + $(this).val());
    $.ajax({
        type:"POST",
        url : "/booking/getdestination",
        data : "selectsourcecity"+ $(this).val(),
        async: false,
        success : function(response) {
            data = response;
            console.log('data ' + data);
            return response;
        },
        error: function() {
            alert('Error occured');
        }
    });
});


server.js
getDestinationCities: function getDestinationCities(req, res, next){
    var sourceCityId = req.query.selectsourcecity;
    console.log('source city id ' + req.body.selectsourcecity);             
                  //says [object] unable to retrieve value

    rest.get('http://CTB_SERVER_URL/rest/destinationcities').on('complete', 
function   (destinationCities) {                    //I'm using restler npm
      if (destinationCities instanceof Error) {
        console.log('Error:', destinationCities.message);
        } else {
        req.sourceCities.cityId = req.sourceCities.cityId;
        //console.log(destinationCities);
        console.log(req.sourceCities.cityId);
        req.destinationCities=destinationCities;
        next();
        }
    });
  },

I need code in server where I'm able to catch the data and response back 
json to be populated in the select option

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to