Call Javascript function in PHP -
i need call javascript function , use results(json) variable php. have following function:
<script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script> <script> $(function () { var baseurl = 'https://xxxxxxxxx/'; var uid = 'xxxx'; var pwd = 'xxxx'; getprod('dt.x0ceb.009', '1'); function getprod(cod_prod, qtd) { jquery.support.cors = true; $.ajax({ url: baseurl + 'api/prod?ref=' + encodeuricomponent(cod_prod) + '&qtd=' + qtd, type: 'get', jsonp: "callback", datatype: 'jsonp', username: uid, password: pwd, success: function (data, textstatus, xhr) { document.write(data); }, error: function (xhr, textstatus, errorthrown) { alert(xhr.responsetext); } }); } }); </script>
this returns this:
object { ref: "dt.x0ceb.009", desc: "monitor ultrahd p2715q 68.6cm 27"", state: 0, price: object, tax: object, stock: 2, availability: null }
can me how use fields (ref, desc, state, ...)in php? regards pedro
you sending them params therefore should available in endpoint via $_get. try sending data object via post , retrieve them $_post in php api.
$.ajax({ url: 'yoururl', method: 'post', data: { param1: param1, param2: param2 }, success: function(data) { //do data } }); php $param1 = $_post['param1']; $param2 = $_post['param2'];
Comments
Post a Comment