HTML
<form id="join">
<div class="content">
<h2>Join the Dodilio Exchange</h2>
<ul>
<li><input id="firstname" type="text" placeholder="Fast Name" name="firstname" required></li>
</ul>
</div>
</form>
JS
var register = function (firstname) {
var obj = {
"firstname": firstname
}
$.ajax({
type: "POST",
dataType: 'json',
data: obj,
url: "/rest/register/?format=json",
success: function (data) {
console.log('success')
//window.location.href = '/ideas'
}
});
}
var joinForm = $('#join');
var firstname = $('#firstname').val()
joinForm.submit(function(e){
console.log('submit')
e.preventDefault();
register(firstname)
return false;
})
BUT it is Posting a traditional form:
POST http://127.0.0.1:8000/rest/register/?format=json HTTP/1.1
Host: 127.0.0.1:8000
Connection: keep-alive
Content-Length: 233
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://127.0.0.1:8000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://127.0.0.1:8000/jointheexchange.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
firstname=&lastname=&
I am not super strong with jQuery, and I have looked at a few examples of this on the web and stack and honestly cannot see what I am dong wrong / differently. PLease help - thx.