[英]My PHP script for ajax is returning blank value
sbms.php sbms.php
<?php
header('Access-Control-Allow-Origin: *');
if(isset($_POST['signup']))
{
$id = $_POST['val'];
echo $id;
}
?>
index.html index.html
<form>
<label class="item-input">
<span class="input-label">ID</span>
<input type="text" id="cid">
</label>
<label class="item-input">
<button class="button button-block button-positive" id="signup">Submit</button>
</label>
</form>
<div class="card">
<div class="item item-text-wrap">
<p id="res"></p>
</div>
</form>
ajax script:- ajax脚本:-
$(document).ready(function(){
$('#signup').click(function(){
var data = $('#cid').val();
$.ajax({
type : "POST",
data : val,
url : 'http://127.0.0.1/ionic/sbms.php',
crossDomain : true,
success : function (data) {
alert(data);
}
});
});
});
I am just trying to a dummy response from the server but the response I get is totally blank. 我只是想对服务器进行虚拟响应,但是得到的响应完全空白。 I am not able to figure out the problem
我无法解决问题
You're not sending a signup
value, you're just sending in an unnamed value so your PHP script is not entering the if
condition. 您不是在发送
signup
值,而是在发送未命名的值,因此您的PHP脚本不会输入if
条件。 Try changing your ajax call to this: 尝试将您的ajax调用更改为:
$.ajax({
type : "POST",
data : { val: val, signup: true }
url : 'http://127.0.0.1/ionic/sbms.php',
crossDomain : true,
success : function (data) {
alert(data);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.