Hi,

In a template I have two ajax calls (one POST, one GET) corresponding to
"Save" button and a "Go Back" button which are on two different forms.

While the POST data on clicking "Save" gets passed to url1, GET data on
clicking "Go Back" is being received in url2 simply as False instead of
valid string.


In template, (just before </head>)

<script>
    var pid_imgfn = "{% static pid_imgfn %}";
    var patient_id = "{{ patient_id }}"
</script>



In template (just before </body>):

<script>
    $('#submitButton').click(function(event){
        event.preventDefault(); //so that we stop normal form submit.
        $.ajax(
             url: 'retina:rh',
             type: 'post',
             data: my_x : my_x, my_y : my_y,  patient_id : patient_id,
pid_imgfn : pid_imgfn
             success: function(data) {
                  $('#message').html("<h2>Contact Form Submitted!</h2>")
             }
        );
    });
</script>
<script>
    $('#backButton').click(function(event){
        event.preventDefault(); //so that we stop normal form submit.
        $.ajax(
             url: 'retina:cf',
             type: 'GET',
             data:  patient_id : patient_id, pid_imgfn : pid_imgfn
             success: function(data) {
                  $('#message').html("<h2>Get method</h2>")
             }
        );
    });

</script>


Forms:

<form id="maform" action="{% url  'retina:rh' %}"  method="post"  >
    {% csrf_token %}

 <input type="submit"   class="button" value = "Save" id="submitButton" >
</form>
<form id="maformb" action="{% url  'retina:cf' %}"  method="get"  >
    {% csrf_token %}
    <input type="submit"   class="button" value = "Go Back"  id="backButton" >
</form>



In views.py

if request.method == 'POST':
    my_x = 'my_x' in request.POST and request.POST.get('my_x')
    my_y = 'my_y' in request.POST and request.POST.get('my_y')
    patient_id = 'patient_id' in request.POST and request.POST.get('patient_id')

The above patient_id is received correctly.

elif request.method=='GET':
    patient_id = 'patient_id' in request.GET and request.GET.get('patient_id')
    pid_imgfn = 'pid_imgfn' in request.GET and request.GET.get('pid_imgfn')
    print(patient_id)

But the above patient_id is not received correctly, but as False.

Kindly help me what might be the cause of this.

Thanks,
sundar

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPdFxcDxKLUNsZSUKqHw9s_2jb%2BVgCfhqMMtmTL75FdrPc2axQ%40mail.gmail.com.

Reply via email to