I'm trying to fetch json from ajax request from server and send it back to 
view on selct option change. Please help me with this. I'm not able to 
retrieve json sent from server.

Ihave been stuck in this for really really long. Please help me clean the 
code, i'm very new to jquery



view.jade

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 request

$('#selectsourcecity').change(function() {
    var data = "";
    console.log('value ' + $(this).val());
    $.ajax({
        type:"POST",
        url : "/booking/getdestination",
        dataType: "json",
        data : {selectsourcecity : $(this).val()},
        async: false,
        success : function(response) {
            data = response;
            console.log('success ' + JSON.stringify(data));
            return response;
        },
        error: function() {
            alert('Error occured');
        }
    });
    var string = JSON.stringify(data);
    console.log('string'+ string);
    var array = string;
    var select = $('selectdestinationcity');
    select.empty();
    $.each(array, function(index, value) {          
        select.append(
                $('<option></option>').val(value).html(value)
            );
    });
        $('#selectdestinationcity').show();
});



server.js

 getDestinationCities: function getDestinationCities(req, res, next){
   
    console.log('source city id ' + req.body.selectsourcecity);
    rest.get('http://eSERVER_URL').on('complete', function   
(destinationCities) {
      if (destinationCities instanceof Error) {
        console.log('Error:', destinationCities.message);
        } else {
        var sourceCitiesId = req.body.selectsourcecity;
        console.log('destination ' + 
JSON.stringify(destinationCities[sourceCitiesId]));
        
res.json(destinationCities[sourceCitiesId]);                             
//have gotten the data successfully i just need to catch this in ajax 
response
        next();
        }
    });

-- 
-- 
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