javascript - How to send and recive content using ajax and php -
i try send data server ajax (pure js)
, want send on request body know how in jquery:
$.ajax({ url: 'someurl', data: 'foo' }); what mean how can send data server jquert when useing ajax method data attribute in pure js ?
also, how in php data?
know laravel need do
request::getcontent(); (if remember right) dont know how data in php
thanks
in terms of sending ajax request via javascript without relying on jquery, that's pretty broad question. should review documentation here.
a simple example
// old compatibility code, no longer needed. if (window.xmlhttprequest) { // mozilla, safari, ie7+ ... httprequest = new xmlhttprequest(); } else if (window.activexobject) { // ie 6 , older httprequest = new activexobject("microsoft.xmlhttp"); } httprequest.open('post', url); httprequest.setrequestheader('content-type', 'application/x-www-form-urlencoded'); var data = /* data here */ httprequest.send('data=' + encodeuricomponent(data)); to retrieve in php use either $_post or file_get_contents('php://input') depending on content-type header sent in request. above example use application/x-www-form-urlencoded content-type header, post http verb, information populated in $_post['data'].
Comments
Post a Comment