ajax传值和回调原理
刚开始学习ajax,
大牛门帮我看看有没有问题?
$.get("__URL__/yanz",{bid:bid,b:v,},function(data,status){ alert(data.aa); alert(status); },"json");
if ($cdata){ echo json_encode($cdata); $this->ajaxReturn($cdata,'查询成功',1);//主要是这里回调 }else{$this->error("数据不存在");}
用是thinkphp的,本想做一个把ID和名称通过ajax传值,然后查询数据库中是否存在。不存在跳转URL。
问题:值收到了,但回调和跳转URL不知道怎么搞。大牛请指导,
回复讨论(解决方案)
设置 config
‘DEFAULT_AJAX_RETURN’ => 'JSON'
将返回如下结构
{
"status“ : "1",
"info" : "查询成功",
"data" : 你的$cdata形成的数据体
}
假设你的数据体中有 aa 一项,则 alert(data.data.aa)
注意:不要 echo json_encode($cdata);
切记!因为你要返回的是 json,所以不能有其他任何输出,否则 json 将解码失败
设置 config
‘DEFAULT_AJAX_RETURN’ => 'JSON'
将返回如下结构
{
"status“ : "1",
"info" : "查询成功",
"data" : 你的$cdata形成的数据体
}
假设你的数据体中有 aa 一项,则 alert(data.data.aa)
注意:不要 echo json_encode($cdata);
切记!因为你要返回的是 json,所以不能有其他任何输出,否则 json 将解码失败
非常感谢版主,改了返回结构可以了。
我还有个问题:能不能直接返回$this->success()和$this->error()链接和内容?
不知道,那是你框架的事情
没用过,不好说

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Analysis of the role and principle of nohup In Unix and Unix-like operating systems, nohup is a commonly used command that is used to run commands in the background. Even if the user exits the current session or closes the terminal window, the command can still continue to be executed. In this article, we will analyze the function and principle of the nohup command in detail. 1. The role of nohup: Running commands in the background: Through the nohup command, we can let long-running commands continue to execute in the background without being affected by the user exiting the terminal session. This needs to be run

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

Principle analysis and practical exploration of the Struts framework. As a commonly used MVC framework in JavaWeb development, the Struts framework has good design patterns and scalability and is widely used in enterprise-level application development. This article will analyze the principles of the Struts framework and explore it with actual code examples to help readers better understand and apply the framework. 1. Analysis of the principles of the Struts framework 1. MVC architecture The Struts framework is based on MVC (Model-View-Con

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

MyBatis is a popular Java persistence layer framework that is widely used in various Java projects. Among them, batch insertion is a common operation that can effectively improve the performance of database operations. This article will deeply explore the implementation principle of batch Insert in MyBatis, and analyze it in detail with specific code examples. Batch Insert in MyBatis In MyBatis, batch Insert operations are usually implemented using dynamic SQL. By constructing a line S containing multiple inserted values

The RPM (RedHatPackageManager) tool in Linux systems is a powerful tool for installing, upgrading, uninstalling and managing system software packages. It is a commonly used software package management tool in RedHatLinux systems and is also used by many other Linux distributions. The role of the RPM tool is very important. It allows system administrators and users to easily manage software packages on the system. Through RPM, users can easily install new software packages and upgrade existing software
