代码区项目交易流程

Hide the output of echo json_encode


I was passing an array inphp to javascript using json_encode and ajax. It seems that the only way is to use

echo json_encode($var)

which also prints out the information of $var on the page because of echo. Is there an easy way to hide the output? My code was like the follows,

main.php

<?php include_once('testing.php'); ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript" src="testing.js"></script> </body> <html>

testing.php

<?php $var=array('1','2','3','4','5'); echo json_encode($var); ?>

testing.js

$.ajax({ url : './testing.php', type : "GET", dataType : 'json', success : function (result) { showstaff(result); } }); function showstaff(x){ console.log(x); }

Running main.php print out the array('1','2','3','4','5') on the page and show the array in the console, but what I need is to just show the array in the console (i.e. hide the results from the page).

You don't need include_once('testing.php') in main.php . When main.php is sent to the browser, it will load testing.js , which will then execute testing.php via the AJAX call.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

点击收藏

LAST Medium Inspired Image Zoom In Plain JavaScript v-zoom Downloading a file from Autodesk A360 to a shopping cart in NodeJS NEXT