php - PUT with jquery returns error -
i trying update field small jquery script keeps returning error , cannot see have problem.
i have anchor onclick="reportad(myaid)" runs this:
function reportad(aid) { var conf = confirm("will report ad?"); if(conf == true) { $.ajax({ url: rooturl + '/reportad/', type: 'put', datatype: 'json', contenttype: 'application/json', data: {'aid': ''+aid+''}, success: function(data) { alert("ad have been reported"); }, error: function(data) { console.log(data); } }); } return false; }
which should run this:
$app->put('/reportad/', function() use ($app, $adverts) { $request = slim::getinstance()->request(); $data = json_decode($request->getbody()); $adverts->report_ad($data->aid); });
firebug gives me this:
object { readystate=4, status=200, statustext="ok"}
if call script curl
curl -i -x put -h 'content-type: application/json' -d '{"aid":"43"}' http://www.domain.dk/reportad/
it works.
you're asking content of answer parsed json. if it's not json, you're encountering parseerror.
try remove datatype
argument.
Comments
Post a Comment