Javascript 使用TwilioAPI、PHP和HTML调用变量
我在调用PHP文件中以表单形式输入的数字时出错: 下面是调用my PHP sendnotifications.PHP中的号码的代码行:Javascript 使用TwilioAPI、PHP和HTML调用变量,javascript,php,html,variables,twilio,Javascript,Php,Html,Variables,Twilio,我在调用PHP文件中以表单形式输入的数字时出错: 下面是调用my PHP sendnotifications.PHP中的号码的代码行: $phone=$_POST["phone"]; 和我的HTML测试表单source.HTML: <!doctype html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jque
$phone=$_POST["phone"];
和我的HTML测试表单source.HTML:
<!doctype html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[///////////Javascript
$(function(){
$("#frm").submit(function(e){
e.preventDefault();
$.post("sendnotifications.php", $("#frm").serialize(),
function(data){
if(data.sms_sent == 'OK'){
alert("Message Sent");
} else {
alert("Message Not Sent");
}
}, "json");
});
});
// ]]>
</script>
</head>
<html>
<form id="frm" name="frm">
<input type="hidden" name="ajax" value="1" />
<input type="phone" name="phone" />
<button type="submit">Get Link</button>
<div class="error" style="display: none;"></div>
</form>
</html>
//
获取链接
Chrome控制台中的错误:
jquery.min.js:130 Failed to load file:///Users/Joris/Desktop/Test%20envoi%20sms%20accueil/sendnotifications.php: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
ajax @ jquery.min.js:130
post @ jquery.min.js:122
(anonymous) @ source.html:8
handle @ jquery.min.js:55
o @ jquery.min.js:49
source.html:10 Uncaught TypeError: Cannot read property 'sms_sent' of null
at Object.success (source.html:10)
at b (jquery.min.js:124)
at XMLHttpRequest.x.onreadystatechange (jquery.min.js:129)
at Function.ajax (jquery.min.js:130)
at Function.post (jquery.min.js:122)
at HTMLFormElement.<anonymous> (source.html:8)
at HTMLFormElement.handle (jquery.min.js:55)
at HTMLFormElement.o (jquery.min.js:49)
(anonymous) @ source.html:10
b @ jquery.min.js:124
x.onreadystatechange @ jquery.min.js:129
ajax @ jquery.min.js:130
post @ jquery.min.js:122
(anonymous) @ source.html:8
handle @ jquery.min.js:55
o @ jquery.min.js:49
XMLHttpRequest.send (async)
ajax @ jquery.min.js:130
post @ jquery.min.js:122
(anonymous) @ source.html:8
handle @ jquery.min.js:55
o @ jquery.min.js:49
jquery.min.js:130加载失败file:///Users/Joris/Desktop/Test%20envoi%20sms%20accueil/sendnotifications.php: 跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https。
ajax@jquery.min.js:130
post@jquery.min.js:122
(匿名)@source.html:8
handle@jquery.min.js:55
o@jquery.min.js:49
source.html:10未捕获类型错误:无法读取null的属性“sms\u sent”
at Object.success(source.html:10)
在b(jquery.min.js:124)
位于XMLHttpRequest.x.onreadystatechange(jquery.min.js:129)
在Function.ajax(jquery.min.js:130)
在Function.post(jquery.min.js:122)
在HTMLFormElement。中,您似乎是使用文件://
协议打开html页面,而不是从web服务器打开。在运行php的本地主机上打开它。我正在尝试,但如果你能帮我,我不知道怎么做。我使用Mac os、Visual Studio代码和Dreamwea。很好,我用MAMP完成了,谢谢