Heim > Backend-Entwicklung > PHP-Tutorial > js向php发送post请求失败,求解,该怎么处理

js向php发送post请求失败,求解,该怎么处理

WBOY
Freigeben: 2016-06-13 12:08:50
Original
931 Leute haben es durchsucht

js向php发送post请求失败,求解

function alertWin(title, msg, w, h) { <br />        var titleheight = "22px"; // 窗口标题高度 <br />        var bordercolor = "#666699"; //窗口的边框颜色 <br />        var titlecolor = "#FFFFFF"; // 窗口的标题颜色 <br />        var titlebgcolor = "#666699"; // 窗口的标题背景色 <br />        var bgcolor = "#FFFFFF"; // 内容背景色 <br />        var iWidth = document.documentElement.clientWidth; //这个窗口的宽度 <br />        var iHeight = document.documentElement.clientHeight; //这个窗口的高度 <br />        //创建一个弹出层 <br />        var msgObj = document.createElement("div"); <br />        //设置弹出的层的样式 <br />        msgObj.style.cssText = "position:absolute;font:11px '宋体';top:" + (iHeight - h) / 2 + "px;left:" + (iWidth - w) / 2 + "px;width:" + w + "px;height:" + h + "px;text-align:center;border:1px solid " + bordercolor + ";background-color:" + bgcolor + ";padding:1px;line-height:22px;z-index:1001;"; <br />        document.body.appendChild(msgObj); <br />        //创建一个table用于容纳层上的内容 <br />        var table = document.createElement("table"); <br />        //将Table放到弹出层上 <br />        msgObj.appendChild(table); <br />        //设置table的格式 <br />        table.style.cssText = "margin:0px;border:0px;padding:0px;"; <br />        table.cellSpacing = 0; <br />        //插入一行用于显示标题 <br />        var tr = table.insertRow(-1); <br />        //插入一个单元格用于容纳标题 <br />        var titleBar = tr.insertCell(-1); <br />        titleBar.style.cssText = "width:100%;height:" + titleheight + "px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:" + titlecolor + ";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor; <br />        titleBar.style.paddingLeft = "10px"; <br />        //设置标题 <br />        titleBar.innerHTML = title; <br />        //关闭按钮事件 <br />        var closeBtn = tr.insertCell(-1); <br />        closeBtn.style.cssText = "cursor:pointer; text-align:right;padding:2px;background-color:" + titlebgcolor; <br />        closeBtn.innerHTML = "<span style='font-size:15pt;color:" + titlecolor + ";'>×</span>"; <br />        closeBtn.onclick = function() { <br />            document.body.removeChild(msgObj); <br />        } <br />        //弹出的消息窗口内容 <br />        var msgBox = table.insertRow(-1).insertCell(-1); <br />        msgBox.style.cssText = "font:10pt '宋体';"; <br />        msgBox.colSpan = 2; <br />        msgBox.innerHTML = msg; <br />        var nameBox1 = table.insertRow(-1); <br />        var nameLable1 = nameBox1.insertCell(-1); <br />        nameLable1.style.cssText = "font:10pt '宋体';text-align:center;"; <br />        nameLable1.innerHTML = "<tr><td align=\"right\">手机</td><td><input id=\"mobile\" name=\"mobile\" type=\"text\" size=\"15\" class=\"inputBg\" /><span style=\"color:#FF0000\"> *</span> <input id=\"zphone\" type=\"button\" value=\" 获取手机验证码 \" onClick=\"get_mobile_code();\"></td></tr>"; <br />		<br />		var nameBox2 = table.insertRow(-1); <br />        var nameLable2 = nameBox2.insertCell(-1); <br />        nameLable2.style.cssText = "font:10pt '宋体';text-align:center;"; <br />        nameLable2.innerHTML = "<tr><td align=\"right\">验证码</td><td><input type=\"text\" size=\"6\" name=\"mobile_code\" class=\"inputBg\" /></td></tr>"; <br />        <br />		var nameBox3 = table.insertRow(-1); <br />        var nameLable3 = nameBox3.insertCell(-1); <br />        nameLable3.style.cssText = "font:10pt '宋体';text-align:center;"; <br />        nameLable3.innerHTML = "<tr><td align=\"right\"></td><td><input type=\"submit\" value=\" 注册 \" class=\"button\"></td></tr>"; <br />	}<br /><br />	function get_mobile_code(){<br />		alert("111");<br />		$.post('http://'+serverIp+'smsExecute.php', {mobile:jQuery.trim($('#mobile').val()),send_code:<?php echo $_SESSION['send_code'];?>}, function(msg) {<br />            alert(jQuery.trim(unescape(msg)));<br />        });<br />        alert("222");<br />	}
Nach dem Login kopieren

------解决思路----------------------
send_code:''}

确认 jQuery 加载无误
------解决思路----------------------

引用:
Quote: 引用:

看看有没有session_start()  再有就是大括号里面传值实际上键值要用引号的

-------------------------------------------------------------------------------------------------------------
session_start()是有的。加了引号也没效果:{"mobile":jQuery.trim($('#mobile').val()),"send_code":}

你在右键查看源码的时候那个php脚本正确解析了吗?这个很关键
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage