On Jan 17, 2014, at 10:58 PM, Jyoti Chhetri <[email protected]> wrote:
> [… snip happens…]
>
> $('#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); <—— X
> console.log('string'+ string);
A couple of questions:
1. In the success function, you are printing the result data. What do you see
on your browser console?
2. The AJAX is an async call. I hope you are not assuming, in the line that I
have marked X above, that the results of the AJAX call are already available to
you? In case you are, that is likely your problem, and you should move all or
most of the code at and after line X into the success function.
Caveat: I have only taken a very cursory glance at the code, I do not care for
Jade and so I skipped that whole section, and I am assuming that your
server-side is working as expected.
—ravi
> 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.
--
--
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.