0
votes

I'm sending a POST request with data, but I don't receive any data.

Calling the request:

$.ajax({
    type:"POST",
    url:"ajaxtest.lp",
    dataType:'json',
    contentType:'json',
    data:"{name:'lolbert',surname:'roflcopter'}"
})

What's going out:

HEADER:

Connection  
close
Content-Type    
text/html
Date    
Thu, 01 Jan 1970 07:24:40 GMT
Server  
Core4Web
Quelltext anzeigen
Accept  
application/json, text/javascript, */*; q=0.01
Accept-Encoding 
gzip, deflate
Accept-Language 
de,en-US;q=0.7,en;q=0.3
Content-Length  
31
Content-Type    
json; charset=UTF-8
Host    
192.168.207.117
Referer 
http://192.168.207.117/ajaxtest.lp
User-Agent  
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0
X-Requested-With    
XMLHttpRequest

POST (via Firebug):

name=lolbert&surname=roflcopter

But what I'm receiving on the server side is somehow strange. The content-length is correct (37 chars) but the content itself is missing.

**** request
script_file request script_file ajaxtest.lp
client_content_type request client_content_type json; charset=UTF-8
client_port request client_port 64626
method request method post
client_address request client_address 192.168.203.59
client_content_length request client_content_length 37
urn request urn /ajaxtest.lp
script_vpath request script_vpath /ajaxtest.lp
script_path request script_path /usr/lib/htdocs/ajaxtest.lp
script_pdir request script_pdir /usr/lib/htdocs/
script_vdir request script_vdir /
**** header
Content-Type header Content-Type json; charset=UTF-8
Accept-Encoding header Accept-Encoding gzip, deflate
X-Requested-With header X-Requested-With XMLHttpRequest
Accept-Language header Accept-Language de,en-US;q=0.7,en;q=0.3
Connection header Connection keep-alive
Pragma header Pragma no-cache
Content-Length header Content-Length 37
Host header Host 192.168.207.117
User-Agent header User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0
Accept header Accept application/json, text/javascript, /; q=0.01
Referer header Referer http://192.168.207.117/ajaxtest.lp
Cache-Control header Cache-Control no-cache
**** file
script_path file script_path /usr/lib/htdocs/ajaxtest.lua
script_pdir file script_pdir /usr/lib/htdocs/
urn file urn ajaxtest.lua
script_vpath file script_vpath /ajaxtest.lua
nesting_level file nesting_level 1
script_file file script_file ajaxtest.lua
script_vdir file script_vdir /

2
You should pass object as data to $.post method, not string: data:{"name":"lolbert","surname":"roflcopter"}. And set it as valid JSON notation, because you are setting contentType:'json', (even not sure how jQuery would handle it?!) - A. Wolff

2 Answers

0
votes
$.ajax({
    type:"POST",
    url:"ajaxtest.lp",
    dataType:'json',
    contentType:'json',
    data:{name:'lolbert',surname:'roflcopter'}
});

Please try to send data with object.

0
votes

Is not a correct JSON data: http://www.json.org/ try with:

data: '{"name": "lolbert","surname": "roflcopter"}'

You can check the correct JSON format with online tools (like http://jsonlint.com/ for example).