jquery的ajax用get方法无法将值传到后台,why

WBOY
Release: 2016-06-23 14:03:09
Original
797 people have browsed it

如题:
//以下是js的方法
function login() {
$.ajax({
     type: "get",
     url:'valid.php', 
     data:"username=admin", 
     dataType:"json", 
     success:ajaxComplete(result), 
     error:ajaxError(response)});
   });
}

//以下是valid.php
echo $_GET['username'];
?>

触发login()方法后,页面报错 Notice: Undefined index: username,意思是找不到这个参数,这是为什么呢,求解!!


回复讨论(解决方案)

data:"username=admin",  这里错了 要么 你  data"username:admin"  
要么就先序列化

你连 js 都写错了,怎么可以得到结果?

function login() {  $.ajax({    type: "get",    url:'valid.php',     data:"username=admin",     dataType:"json",     success:ajaxComplete,     error:ajaxError  });}
Copy after login

success 和 error 需要的都是回调函数
你要么赋予函数名,要么直接定义匿名函数

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template