qui è il mio codice:ottenere l'array JavaScript Django
urls.py:
from django.conf.urls import patterns
from views import show,showpage
urlpatterns = patterns('',
(r'^$',showpage),
(r'^show/$',show),
)
views.py
from django.http import HttpResponse
def show(request):
arr = reqeust.GET.get('arr','Nothing')
print arr#**it's 'Nothing'**
if arr == 'Nothing':
msg = 'fail'
else:
msg = 'pass'
return HttpResponse(msg)
def showpage(request):
html = ''' <html>
<head>
<script language="javascript" type="text/javascript" src="/site_media/js/jquery-1.7.2.js"></script>
</head>
<body>
<input type="button" id="input_btn"/>
</body>
<script language="javascript" type="text/javascript">
$(function(){
$("#input_btn").bind("click",function(){
arr = [1,2,3,4,5,6]
$.ajax({
type:"GET",
url:"/show/",
data:{arr:arr},//**I want pass the arr to django**
success:function(data){alert(data);},
error:function(data){alert(data);}
});
});
})
</script>
</html>'''
return HttpResponse(html)
quando accedo localhost: 8000, e fare clic sul pulsante, ho stampato 'Nothing' nella console di back-end, come sai che ha ottenuto il messaggio 'fallire' nel frontend
uh..can nessuno sovle questo problema, voglio ottenere il codice (arr = reqeust.GET.get('arr','Nothing')
) che restituiscono una lista ([1,2,3,4,5,6]
) o qualcosa di simile
------ --- append1 -------
ho ottenuto questo nella console quando clicco il btn
[12/Giu/2012 09:48:44] "GET/show /? arr % 5B% 5D = 1 & arr% 5B% 5D = 2 & arr% 5B% 5D = 3 & arr% 5B% 5D = 4 & arr% 5B% 5D = 5 & arr% 5B% 5D = 6 HTTP/1.1" 200 4
--------- ------- apend2
Ho fissato il mio codice come questo:
arr = request.GET.get('arr[]','Nothing')
ed ho ottenuto 6, che è l'ultimo della matrice javascript, come posso ottenere l'intero array?
grazie anticipo!
Che aspetto ha l'URL della richiesta reale? –
scusa! Ho dimenticato di tornare alla pagina html, aspetta un minuto – sashimi
@Ignacio Vazquez-Abrams Ho risolto la mia domanda e ho inserito l'URL di richiesta nella parte inferiore del contenuto della domanda – sashimi