thinkphp真用着不顺手,老有问题,为什么thinkphp ajaxreturn 返回的是json格式的字符串,而不是json对象。本地是返回对象,服务器上是返回字符串,求解……
回复讨论(解决方案)
无人问津……
json格式的字符串?什么概念?
json格式的字符串?什么概念?
如图:本地用alert出的数据
服务器上,alert出来的是
应该是有可以控制的地方吧
没用过这个框架 自己 eva 或者 JSON.parse 一下吧
应该是有可以控制的地方吧
没用过这个框架 自己 eva 或者 JSON.parse 一下吧
这个我知道,可是本地跟服务器上为啥就不一样了,是不是服务器配置问题,不可能本地跟服务器上使用两套代码啊?
应该是有可以控制的地方吧
没用过这个框架 自己 eva 或者 JSON.parse 一下吧
这个我知道,可是本地跟服务器上为啥就不一样了,是不是服务器配置问题,不可能本地跟服务器上使用两套代码啊?
服务器配置应该没这个关系啊,thinkphp有没有这个设置?
LZ。建议你去THINKPHP官方的论坛咨询比较有效率。。。
dataType: 'json'
dataType: 'json'
这个他应该是知道的
在你不转化为json之前,输出结果集看看。
http传输的都是文本,何来的object?
json本身就是一个文本格式的数据表现形式,只有通过js引擎解释执行后才会变为js的object
你 #3 的截图表示 json 数据串已经正确返回了
那么为什么图二的串未被转换成对象呢?
这与你的服务器默认的返回头有关系,当然也与你使用的浏览器有关系
你可以在返回前先输出声明 json 数据类型的头
也可以在 js 中通过判定数据类型来决定是否需要自己再做一次转换
当然,以上的讨论是建立在你的程序没有变化的基础上的
另外,这不能怪 thinkphp,因为 thinkphp 不可能预知有哪些浏览器会那么不人性化化的,刻板的按http头来解释数据
总结下,结贴了,
第一个可能问题在:thinkphp封装的json返回对象,有些浏览器不支持,所以不用官方的这个方法
第二个问题是:我们公司同事用的开发环境不一样,系统不同,有些文件产生了bom的问题,导致ajax返回值多了空格
我的也是多个空格,蛋痛

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use
