Closed freinn closed 8 years ago
Hi!
I'm having trouble using this library because I don't know well how to insert POST parameters and then retrieve them on the server.
This is the important part of my PHP file:
->addPostRoute('db/(.+)', function($tok) { var_dump($tok); $myfile = fopen("./newfile.txt", "w") or die("Unable to open file!"); fwrite($myfile, $tok . "\n"); die(); }
The important thing for me is to make this work and know how to access the POST parameters.
And on Javascript, I try to perform AJAX with jQuery this way:
var objeto = { "token":"tokenSano", "campo": "contenido" }; var postDATA = JSON.stringify(objeto); jQuery.ajax({ url : "http://192.168.0.191/servicioWebREST/index.php/db", type: "POST", data : JSON.stringify(objeto), crossDomain: true, //contentType: "application/json; charset=utf-8", dataType: "text", // cache: false, processData: false, // beforeSend: beforeSendHandler, success: function(data, textStatus, jqXHR) { console.log('success'); }, error: function (jqXHR, textStatus, errorThrown) { console.log('failure'); } });
When I send this to the server, it always responds with error 400 Bad Request.
Just use $_POST['tok'] and don't use /(.+).
/(.+)
Thanks, I will make a pull request trying to improve the docs.
Hi!
I'm having trouble using this library because I don't know well how to insert POST parameters and then retrieve them on the server.
This is the important part of my PHP file:
The important thing for me is to make this work and know how to access the POST parameters.
And on Javascript, I try to perform AJAX with jQuery this way:
When I send this to the server, it always responds with error 400 Bad Request.