I am using the latest version of OpenResty to perform some manipulations on POST request data using Nginx Lua. My test Lua script, being called via a rewrite_by_lua_file call is simple
ngx.req.read_body();
local args = ngx.req.get_post_args();
ngx.say(args["a"]);
To test it I have a simple HTML document
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$('#btnPOST').click(doPOST);
$('#btnAJAX').click(doAJAX);
});
function doPOST()
{
$.post('index.php',{a:2,b:3},afterAJAX);
}
function doAJAX()
{
var fd = new FormData();
fd.append('a',2);
fd.append('b',3);
$.ajax(
{url:'index.php',data:fd,cache:false,contentType:false,
processData:false,
type:'POST',success:function(d){afterAJAX(d);},error:netError});
}
function afterAJAX(d,e)
{
debugger;
alert(d);
}
function netError(){alert('error');}
</script>
</head>
<body>
<button id='btnPOST'>Post</button>
<button id='btnAJAX'>Ajax</button>
</body>
</html>
Clicking the POST button gives the expected results - the alert box says '2'.
Clicking the AJAX button which is submitting a form OTH returns d=nil.
I am not sure what is going on here. I suspect the issue here is to do with the way multipart form data are sent out. It seems like Lua/Nginx is missing out on parsing the form data on the multipart boundaries. However, it is not clear what I should do about it at the Lua end. I'd much appreciate some help