0

I'm working on a basic year, make, model dependent drop down menu, but started working backwards. I'm currently working on making my success callback dependent on the model drop down selection. For instance, if I choose 2006, lexus, is250, I only want my success callback to display that vehicle.

Most of my code can be found http://codepen.io/cfavela/pen/bozie/ (make sure to collapse the CSS page to make it easier to read)

My results page (modelsTest.html) contains the following:

{ "Car": "2012 Chevrolet Avalanche", "Price": "$10,999", "Features": "Soft seats!" "Img": "/css/img/2012_Avalanche.jpeg" }

What I've tried to do is add another car using an array and $.each, but the problem with this result is that it returns every vehicle if I click on search. How can I make the success callback dependent on the model selected?

  • your HERE1 is missing the link – Alan Tsai May 16 '14 at 03:26
  • oops, thanks for letting me know. It has been fixed – user3623883 May 16 '14 at 03:29
  • are you using any server side technology? There is no way you can get post data via pure javascript according to this SO answer: http://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript – Alan Tsai May 16 '14 at 03:41
  • Your ajax call is loading `modelsTest.html` (I am assuming it contains HTML) but your dataType is json. I don't think you can do that, you'd get a parse error. And since you're posting to a HTML/plain text file, the data `$('#vehicle').val()` you send does not server any purpose. You will always load **ALL** the content in `modelsTest.html` – PeterKA May 16 '14 at 03:52
  • @Allan Tsai I'm only using HTML and jQuery. I have yet to learn a php, ruby, or python. – user3623883 May 16 '14 at 04:58
  • @user3558931 the success callback returns just fine and in the format I specify. It's when it's multiple objects in that it starts screwing up – user3623883 May 16 '14 at 04:59
  • Can you give a sample of multiple elements, say 2 or 3. – PeterKA May 16 '14 at 05:31
  • If you're asking for a sample, I cannot since I can't get Access-Control on codepen to use ajax. – user3623883 May 16 '14 at 05:42
  • What file extension should my json be located in since it shouldn't be used in html, if I understood correctly? – user3623883 May 16 '14 at 05:50

1 Answers1

0

As I commented above, according to this SO How to read the post request parameters using javascript, you can not get post data at client side level, you would need a server side to do that.

So you could try using GET and form your query ($('#vehicle').val()) as part of query string, then base on the query string, do some javascript logic at modelsTest.html and return the json you want. (but I don't think this will work, because I don't think you can return pure json in a real html file, so guessing your modelsTest.html just contain json. but I could be wrong hence I leave this as a possible solution)

or do the filtering in the success: function() before append to the msg.

Community
  • 1
  • 1
Alan Tsai
  • 2,465
  • 1
  • 13
  • 16