last day (14 days later) » 

1:30 PM
0
Q: Interdependent dropdowns Django JQuery Ajax - getting the url right

phiconI have followed the following tutorial on how to get interdependent dropdowns functional with Django and JQuery / Ajax: http://www.devinterface.com/blog/en/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/ I have the following inline-formset, when a product...

 
Can you use firebug and print the request sent by the Ajax call ?
 
GET 127.0.0.1:8000/order/3/all_json_models 301 MOVED PERMANENTLY 6ms jquery.min.js (regel 16) GET 127.0.0.1:8000/order/3/all_json_models 500 INTERNAL SERVER ERROR 22ms
i think it has someting to do with this line: var url = "/order/" + $(this).val() + "/all_json_models"; i do not know what i should place in the "/order/" part. /order/ is nothing in my application.
 
This var url = "/order/" + $(this).val() + "/all_json_models" will give you the dynamic URL based on the selected option in the HTML select input, $(this) is the selected HTML input select, and .val() is the jQuery API that will give you the value. so I still need what is being sent to the server, the hole request with the parameters !
 
i am not sure what to send, could you give an example?
 
In firebug, Net tab, then in the Ajax request (after you do the select change), Params tab, copy what is in it and print it here !
 
1:30 PM
Accept application/json, text/javascript, /; q=0.01 Accept-Encoding gzip, deflate Accept-Language en-us,en;q=0.7,nl;q=0.3 Connection keep-alive Cookie csrftoken=kVA78XlelB2PDxyTc1iPnijyHxvVcyOw Host 127.0.0.1:8000 Referer 127.0.0.1:8000/orderline_formset/1 User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0 X-Requested-With XMLHttpRequest
 
That is the Headers tab, the tab before the Headers, can show you the sent parameters :)
Hey
 
thanks for helping me nouri
i do not have a tab before the header tab
i have header / answer // html / cache / cookies
 
np mate
sorry mine is in english :/
 
changed the language to english
 
1:58 PM
you still here?
 
yes
sorry i am still at work :D
 
haha ok
ill be patient ;)
 
That is because the request is not the ajax call
can you load the page, then when you change the select value observe the sent request
 
it only shows GET after the change of the select
i will put the site online so you can browse it
 
ok
 
2:11 PM
my static files are not loading correctly
 
There is a problem in your js code
 
will set this up
 
ah ok
tell me when it is up and running
 
ok
its working now
although now i get 404 instead of the 500
ill try to fix that aswell
 
ok
I have the error you posted
 
2:17 PM
yes
thats the error i keep getting
 
can you put a print after the product_type object and print its id to see if it gets or not ?
 
it gets a different one for different selections
 
def all_json_models(request, product_type):
current_product_type = ProductType.objects.get(pk=product_type)
products = Product.objects.all().filter(product_type=current_product_type)
json_models = serializers.serialize("json", products)
return HttpResponse(json_models, mimetype="application/javascript")
after current_product_type
put a print current_product_type.pk
 
added the code
it did not print anythin in console
 
tell me what it prints
 
2:22 PM
[24/Oct/2014 16:22:04] "GET /order/6/all_json_models/ HTTP/1.1" 500 11066
[24/Oct/2014 16:22:10] "GET /order/5/all_json_models HTTP/1.1" 301 0
[24/Oct/2014 16:22:10] "GET /order/5/all_json_models/ HTTP/1.1" 500 11066
and then nothing
 
ok cut all the code and just put "print product_type" then return
 
[24/Oct/2014 16:25:01] "GET /order/2/all_json_models/ HTTP/1.1" 500 11066
then nothing
 
I can't help you like this, do you the code on github or if you can make a pastebin of the file
do you have the code*
 
i can send you a zip file
 
nah don't send me your code, and never do that you can get hacked easily dude
just post the file here: wait
just the views
 
2:30 PM
did not know this site - thanks for the tip
 
np mate
return HttpResponse("{}", mimetype="application/javascript")
replace the last line
In your javascript fucntion, use jQuery Ajax API, $.get it is much more explicit that what the tutorial said
I need to see the javascript file also
 
ok, same error when chaning last line
 
If you want i can help when i get back home now i have to go
 
would be great
thank you
 
you will be waiting ?
or how can you know that i joined the room ?
 
2:53 PM
ill be waiting
 
3:40 PM
...
 

last day (14 days later) »