javascript - PHP not reconizing data from jquery only in DELETE and PUT method -
i full stack student , trying homework... sending php object of daya jquery. it's working fine when method or post, not working when it's delete & put, php get's methos wouldn't data object, gives error: undefined index: activitiesarray. using same functions options, , if change method works.
problems output debug console terminal .. doing wrong?? thanks!
this ajax in javascript: "use static";
function sendajax(method, url, data, calltype) { $.ajax({ type: method, url: url, data: { activitiesarray: data }, success: function(response_text) { callback(response_text, calltype); } }); }
and php api:
$method = $_server['request_method']; // verb $params = $_request['activitiesarray']; switch ($params['ctrl']) { case 'director': $capi = new directorapi(); $result = $capi->gateway($method, $params); echo json_encode($result); break; case 'movie': $capi = new movieapi(); echo $capi->gateway($method, $params); break; }
change code put , delete
function sendajax(method, url, data, calltype) { $.ajax({ type: method, url: url, data: json.stringify({activitiesarray: data}), success: function(response_text) { callback(response_text, calltype); }, datatype: 'json', contenttype: 'application/json' }); }
and on php side, can't use $_request handle put request, can this
$method = $_server['request_method']; // verb $params = $_request['activitiesarray']; if($_server['request_method'] == 'put') { parse_str(file_get_contents("php://input"),$post_vars); echo $post_vars['your_input']; // can access query parameters } else { switch ($params['ctrl']) { case 'director': $capi = new directorapi(); $result = $capi->gateway($method, $params); echo json_encode($result); break; case 'movie': $capi = new movieapi(); echo $capi->gateway($method, $params); break; } }
Comments
Post a Comment