Hey guys, I need a little help. Here is what I'm trying to do.
I would like to have a html button execute a javascript on click, and the javascript should send an GET reguest to the server which should execute the View for the page requested. For some reason I can't get it to work...
here is what I've done
(1) I have a working View that executes successfully when the main page is requested.
(2) The View loads the template that has the html button and javascript.
(3) I have confirmed the when the button is clicked the javascript executes.
However the page doesn't change to the new page requested, and I get a 404 error.... however, the page is there and I link to it from other places in the code.
Maybe I misunderstand something in the way the request and load and ajax stuff works, I'm still a novice.
Here is my code...
//////////////////////// html & javascript ////////////////////////////////////
<script type='text/javascript'>
$(function (){
$("#blog1").click(function (){
var id = $( "#blog1" ).val();
var data = { id:id };
$("#blog1").prop('value', 'works');
$.get({
url:"/control/"
});
});
return false;
});
</script>
//////////////////////////////////////////////////////////////////////////////////////
/////////////////// View /////////////////////////////////////////////////////////
def control_page(request):
sliderB = Slider.objects.get(sliderID=1)
sliderR = Slider.objects.get(sliderID=2)
sliderG = Slider.objects.get(sliderID=3)
sliderP = Slider.objects.get(sliderID=4)
preprogram1 = Preprogram.objects.get(preprogramID=1)
preprogram2 = Preprogram.objects.get(preprogramID=2)
preprogram3 = Preprogram.objects.get(preprogramID=3)
pin1 = Pin.objects.get(pinID=1)
variables = RequestContext(request, {'pin1': pin1, 'preprogram1': preprogram1, 'preprogram2': preprogram2, 'preprogram3': preprogram3, 'sliderB':sliderB, 'sliderR':sliderR, 'sliderG':sliderG, 'sliderP':sliderP})
return render_to_response('control_page.html', variables)
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// urls ///////////////////////////////////////////////////
urlpatterns = patterns('',
(r'^$', main_page),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^logout/$', logout_page),
(r'^user/(\w+)/$', user_page),
(r'^control/$', control_page),
(r'^gpio_control/$', gpio_control_page),
(r'^slider/$', slider_page),
(r'^read_more/$', read_more_page),
(r'^admin/', include(admin.site.urls)),
)///////////////////////////////////////////////////////////////////////////////////////////
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment