php最简单服务器搭建和jquery中的ajax记录备忘

来源:互联网 发布:查理芒格 知乎 编辑:程序博客网 时间:2024/06/01 10:17
php初步服务器创建
1、启动xampp内的xampp-control.exe启动对应的Apache服务器,在config里面修改listen 80就可以修改端口了。(xampp下载地址:https://www.apachefriends.org/zh_cn/index.html)
2、通过deamwaver创建本地站点,可以选择xampp安装目录下的htdocs下面创建一个文件夹来创建,创建的为本地测试服务器
url为localhost:80

3、在站点的文件下创建php文件夹


jquery中的ajax:

type:GET/POST
url: 路径
data:对象,传承
dataType:默认是json
success:方法,包含成功返回的字符串

error:方法,请求失败调用

$.ajax({type:"POST",url:"",data:{name:"",},dataType:"json",success:function(data){if(data.success){}else{}},error:function(jqXHR){//jqXHR.status},});


//跨域
通过jsonp来解决跨域的访问问题a域名去声明,b域名去调用
$.ajax({type:"POST",url:"",data:{name:"",},dataType:"jsonp",jsonp:"callback",//callback可以取任意值供后台取用success:function(data){if(data.success){}else{}},error:function(jqXHR){//jqXHR.status},});
或者使用服务器端修改
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Method:GET,POST");
阅读全文
0 0