Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax is giving back all the html instead of the variable in Django?
    primarykey
    data
    text
    <p>I have a Ajax and template like this:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script language="javascript" type="text/javascript"&gt; &lt;!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } url = '/home' ajaxRequest.open("GET", url, false); ajaxRequest.send(null); } //--&gt; &lt;/script&gt; &lt;form name='myForm'&gt; {% csrf_token %} Name: &lt;input type='text' onChange="ajaxFunction();" name='username' /&gt; &lt;br /&gt; Time: &lt;input type='text' name='time' id='time' value="" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And I have simple views like this:</p> <pre><code>from django.shortcuts import render_to_response, HttpResponse import simplejson from django.template.context import RequestContext import datetime def home(request): if request.GET: a = datetime return HttpResponse(simplejson.dumps(a), mimetype='application/json') #return render_to_response('home.html', {'a':a}, context_instance=RequestContext(request)) else: return render_to_response('home.html', context_instance=RequestContext(request)) </code></pre> <p>Ajax is loading when I press enter but instead of the particular variable all the template is loading in the input box. What's wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload