Return HTML in PHP JSON response

I am building an app to save small notes and comments. The app will require from you to submit a title and it will provide you a text area for your text. Until now when you submit a title I create with jquery a title - text area pair for you to type your text. I was thinking to return the pair through JSON, but someone told me that this is bad practice. Is it really bad practice to return

在PHP JSON响应中返回HTML

我正在构建一个应用程序来保存小笔记和评论。 该应用程序会要求您提交标题,并会为您提供文字区域。 直到现在,当您提交标题时,我使用jquery创建了一个标题 - 文本区域对,供您输入文本。 我想通过JSON返回这对,但有人告诉我这是不好的做法。 通过Jason返回HTML实际上是不好的做法,为什么? JOSN旨在克服用于数据交换的庞大XML格式。 它确实是James所描述的轻量级数据交换格式。 假设:您需要显示包含与产品相关的

What's faster? Ajax loading JSON or Ajax loading complete output

I wanted to see different views / opinions on this. I've got Jquery invoking a function through ajax. It loads data two ways: The ajax script loads JSON data from the same server, then uses JS to parse it and append it into html. The ajax script loads complete html / script set up directly via that php script that's called and then JS appends it to html div. I'd assume #1 is

什么更快? Ajax加载JSON或Ajax加载完成输出

我想看到不同的观点/意见。 我有jquery通过ajax调用函数。 它通过两种方式加载数据: ajax脚本从相同的服务器加载JSON数据,然后使用JS解析并附加到html中。 ajax脚本直接通过被调用的php脚本加载完整的HTML /脚本,然后将JS附加到html div。 我假设#1是加载一个基本的JSON数组,然后使用JS解析它并追加到HTML,因此速度更快。 意见? 谢谢! 有很多变数。 #1的速度可能会更快,前提是您的JavaScript没有将结

Creating HTML: PHP server

This is a design question. I have data that needs to go into an HTML table, which will later be manipulated by the user. Basically the user will be able to select items in the table rows. I have two options - in both cases I'm using AJAX to get the data: Create the HTML code using PHP on the server side, send it to the client as HTML. The user then manipulates the table using Javascrip

创建HTML:PHP服务器

这是一个设计问题。 我有需要进入HTML表格的数据,稍后将由用户操纵。 基本上用户将能够选择表格行中的项目。 我有两个选择 - 在这两种情况下,我使用AJAX来获取数据: 使用PHP在服务器端创建HTML代码,将其作为HTML发送给客户端。 然后用户使用Javascript(本质上是jQuery)操纵表格。 使用JSON将原始数据发送到客户端,然后使用jQuery创建HTML,然后由用户对其进行操作。 从设计/编码/美观的角度来看,推荐哪种方法

Deploy web application as a standalone executable

I have a web application that I developed with the Google Web Toolkit (GWT), it is a utility application that helps make calculations when planning specific server deployments. I want to be able to offer this application as a download on my website for people that want to use the application but don't always have internet access. I was previously able to achieve this by packaging all of fi

将Web应用程序部署为独立的可执行文件

我有一个使用Google Web Toolkit(GWT)开发的Web应用程序,它是一个实用程序应用程序,可帮助您在规划特定服务器部署时进行计算。 我希望能够在我的网站上为想要使用该应用程序的人提供此应用程序,但并不总能访问互联网。 我以前能够通过将GWT编译的所有文件(html和js)打包到Nullsoft安装程序脚本(NSIS)中来实现此目的,该脚本将它们提取到临时目录,然后告诉Windows使用任何浏览器打开主html文件是默认的。 最近这给

Get user's name from Facebook Graph API

I would like to know how is it possible to retrieve a string from an external page. For example: In a PHP website, the user sends a facebook id, ex: 1157251270 And the website returns the name from http://graph.facebook.com/1157251270. I hope I made it clear. Thank you The Graph API returns JSON strings, so you can use: echo json_decode(file_get_contents('http://graph.facebook.com/1157

从Facebook Graph API获取用户的名字

我想知道如何从外部页面检索字符串。 例如:在PHP网站中,用户发送一个facebook id,例如:1157251270 网站返回http://graph.facebook.com/1157251270的名称。 我希望我说清楚。 谢谢 Graph API返回JSON字符串,因此您可以使用: echo json_decode(file_get_contents('http://graph.facebook.com/1157251270'))->name; 或更详细: $pageContent = file_get_contents('http://graph.facebook.com/1157251270'); $p

Dispaly Blob image from database using Symfony Twig

I am trying to display images for each blog post. I have them set up so that it is displaying the blog name, excerpt and published date, but I am struggling to get the images which I have stored as Blobs. I have attached my code, which is in 3 parts: the entity, which has set and get variables; the index.html.twig file, which is the front end (how I am displaying the image); and the post.orm.

使用Symfony Twig从数据库中分辨Blob图像

我正在尝试为每篇博文显示图片。 我让他们设置,以显示博客名称,摘录和发布日期,但我正在努力获取我已经存储为Blob的图像。 我附加了我的代码,它分为三部分:实体,它已经设置并获取变量; index.html.twig文件,这是前端(我如何显示图像); 和post.orm.yml文件,用于设置图像的项目类型,即BLOB。 邮政实体 /** * Set image * * @param /post/blob $image * * @return Post */ public function setimage($image)

add values into multidimentional array

I have a foreach loop that goes through a list of items. For each of these items, I have a while loop that grabs data out of a database. $output = array(); //$reference is a multidimentional array has been passed to this page where the element `color` contains the color I want. foreach ($reference as $c) { $color = $c['color']; $query = "SELECT DISTINCT name FROM $table where colorPrefere

将值添加到多维数组中

我有一个foreach循环遍历项目列表。 对于这些项目中的每一个,我都有一个从数据库中抓取数据的while循环。 $output = array(); //$reference is a multidimentional array has been passed to this page where the element `color` contains the color I want. foreach ($reference as $c) { $color = $c['color']; $query = "SELECT DISTINCT name FROM $table where colorPreference = $color"; $exquery = mysqli_quer

Foreach loop depending on files in directory

Is there a way to create a foreach loop, that will run for however many instances of a filename with a sequential number exists in a directory? For example I have one directory with images. The images will have filenames such as these: firstname-lastname_before1.jpg firstname-lastname_after1.jpg firstname-lastname_before2.jpg firstname-lastname_after2.jpg firstname2-lastname2_before1.jpg firs

Foreach循环取决于目录中的文件

有没有一种方法来创建一个foreach循环,这将运行的目录中存在一个序号的文件名的多个实例? 例如,我有一个目录与图像。 图像将具有如下所示的文件名: firstname-lastname_before1.jpg firstname-lastname_after1.jpg firstname-lastname_before2.jpg firstname-lastname_after2.jpg firstname2-lastname2_before1.jpg firstname2-lastname2_after1.jpg firstname2-lastname2_before2.jpg firstname2-lastname2_after2.jpg

getting wrong results from foreach

I have following code: $arraySlice1 = array_slice($teamsA, 0, 8); $arraySlice2 = array_slice($teamsA, 8, 15); foreach ($arraySlice1 as $teamHome) { $dateCounter = 1; foreach ($arraySlice2 as $teamAway) { $tactic1 = $doctrine->getRepository('LoginLoginBundle:Tactics') ->findByteamTeamid($teamHome->ge

从foreach得到错误的结果

我有以下代码: $arraySlice1 = array_slice($teamsA, 0, 8); $arraySlice2 = array_slice($teamsA, 8, 15); foreach ($arraySlice1 as $teamHome) { $dateCounter = 1; foreach ($arraySlice2 as $teamAway) { $tactic1 = $doctrine->getRepository('LoginLoginBundle:Tactics') ->findByteamTeamid($teamHome->getTeamid(

Adjusting last iteration in a foreach loop in PHP

I have a question and answer forum. A user may browse responses to questions and promote them if they wish. The code below outputs the different users that have promoted a given question - the users are in the array '$promoters' that is returned from the line $promoters = Promotion::find_all_promotions_for_response($response->response_id); . The foreach loop then goes through each

在PHP中调整foreach循环中的最后一次迭代

我有一个问题和答案论坛。 用户可以浏览对问题的回答并且如果他们愿意的话可以将其提升。 下面的代码输出已提升给定问题的不同用户 - 用户在$ promoters = Promotion :: find_all_promotions_for_response($ response-> response_id)行中返回的数组'$ promoters'中。 。 然后foreach循环遍历每一个并输出它们,样式由css类“启动器列表”。 问题是这个.....如果我有一个推动者,我只想要他们的名字输出(没有问