客户端关键jQuery代码
$('#submit').click(function(e){
var username=$('#name').val();
var pwd=$('#pwd').val();
var message=$('#message').val();
$.post("Validate2.php",
{username:username,pwd:pwd,message:message},
function(response){
alert("response.status="+response.status); //输出返回状态对话框
},
"json"
);
e.preventDefault();
});
服务端关键php代码
$query="insert into Messages values(12345,\"what\",\"1222\")";
$result=$mysqli->query($query);
$response['status']="TRUE";
echo json_encode($response);
$result->free();
$mysqli->close();
exit();
运行完之后数据库确实加上新的数据了,
但那个$response['status']=TRUE死活返回不到客户端,
回复讨论(解决方案)
看看有没有 BOM 头
没懂==BOM头跟这个啥关系...我刚搞php3天
这个问题我以前碰到过,不是没有返回给客户端,而是客户端只是收到了一串字符,而没有把那一串json字符转化为json对象,在客户端先使用eval(response)把json对象制造出来,才能调用其response.status属性。
这个问题我以前碰到过,不是没有返回给客户端,而是客户端只是收到了一串字符,而没有把那一串json字符转化为json对象,在客户端先使用eval(response)把json对象制造出来,才能调用其response.status属性。
这个问题我以前碰到过,不是没有返回给客户端,而是客户端只是收到了一串字符,而没有把那一串json字符转化为json对象,在客户端先使用eval(response)把json对象制造出来,才能调用其response.status属性。
可是是这样,如果我把服务端$query="insert into Messages values(12345,\"what\",\"1222\")";
改成对数据库的查询,如“select * from Messages”就能收到TRUE
或者我把TRUE那行向上移到mysqli-〉query()之前就收得到啊
这个问题我以前碰到过,不是没有返回给客户端,而是客户端只是收到了一串字符,而没有把那一串json字符转化为json对象,在客户端先使用eval(response)把json对象制造出来,才能调用其response.status属性。
可是是这样,如果我把服务端$query="insert into Messages values(12345,\"what\",\"1222\")";
改成对数据库的查询,如“select * from Messages”就能收到TRUE
或者我把TRUE那行向上移到mysqli-〉query()之前就收得到啊 怪哉。。。。。没见过的现象
把服务器返回的东西打印出来看看,先不要解释json
把json参数去掉。
var username=$('#name').val();
var pwd=$('#pwd').val();
var message=$('#message').val();
$.post("Validate2.php",
{username:username,pwd:pwd,message:message},
function(response){
alert("response.status="+response.status); //输出返回状态对话框
},
" json"
);
e.preventDefault();
});
然后在php端,使用file_put_contents('sos.txt', json_encode($_REQUEST), true);
运行后,看看sos.txt有什么,正确应该是你提交的参数。
已搞定....为了以后有人搜同样问题我解释下....
楼主小白,以后在调试的时候应该在php第一行加上
ini_set("display_errors", "on"); //输出错误信息
再测试发现
Fatal error: Call to a member function free() on a non-object in /var/www/html/Validate2.php on line 60
就是说返回的是1,0我那个free应该去掉....去掉后就好了..

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)