Been a while since I asked a qustion about uncharted waters again (Ajax with JQuery). I've been doing a little website for a local charity group. On the website I have a small form were people can ask for help. But I am stuck. Probably staring at the error but can't see it. ;)
ajax.js
function submitApplication()
{
$.ajax({
url: 'db/submitApplication.inc.php',
type:'POST',
dataType: 'json',
data: { name: $("#name").val() },
success: function(output_string){ },
error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); }
});
}
submitApplication.inc.php
<?php
include('../inc/conn.inc.php');
$query = "INSERT INTO ljusimorker_applications (ljusimorker_applications_name) VALUES ('" . $_POST['name'] . "')";
$writeData = mysql_query($query) or die(mysql_error());
mysql_close();
?>
I know that the mysql statements are of the deprected variant but it's only for testing the script. I will add the security aspect later before putting the website live. The HTML I'm fetching is below.
HTML
<div class="input-text">Namn (visas ej):</div></td><td><input type="text" id="name" class="input-box">
The error I get is:
Chrome: SyntaxError: Unexpected end of input
Firefox: SyntaxError: JSON.parse: unexpected end of data
Firebug says this under NET -> XHR
Response Headers
Connection Keep-Alive
Content-Length 0
Content-Type text/html
Date Thu, 15 Aug 2013 11:19:14 GMT
Keep-Alive timeout=3, max=100
Server Apache/2.2.24 (FreeBSD) PHP/5.4.15 mod_ssl/2.2.24 OpenSSL/0.9.8y
X-Powered-By PHP/5.4.15
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3
Cache-Control no-cache
Connection keep-alive
Content-Length 23
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Host xxx.xxx.xxx
Pragma no-cache
Referer http://xxx.xxx.xxx/
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
X-Requested-With XMLHttpRequest
Thanks in advance. :)