los*_*aut 7 php ajax jquery return
好的,我有一个PHP脚本,结尾如此:
if ($success)
{
$result = array('success' => true);
}
else
{
$result = array('success' => false, 'message' => 'Something happened');
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
echo json_encode($result);
Run Code Online (Sandbox Code Playgroud)
还有一些jquery,我计划在我的脚本运行时提醒我.
jQuery(document).ready(function() {
$.ajax({
url: './contactengine.php',
type: 'GET',
dataType: 'JSON',
success: function(response) {
alert("GOOD");
},
error: function() {
alert("BAD");
}
});
});
Run Code Online (Sandbox Code Playgroud)
编辑来源
<?php
if ($success){
$result = array("status" => "1");
echo json_encode($result);
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=/404.html\">";
}
?>
<script>
jQuery(document).ready(function() {
$.ajax({
type: 'GET',
url: 'Thatscriptsomething.php',
cache: 'false',
dataType: 'json',
success: function(response) {
if(response.status == "1") {
alert("we having a working script");
} else {
alert("Oops, script is a no go");
}
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
基本示例-对我有用
PHP响应
$value = array('msg' => 'true' );
echo json_encode($value);
Run Code Online (Sandbox Code Playgroud)
AJAX方法
$.ajax({
type: 'post',
url: 'URL',
contentType: false,
processData: false,
dataType:'JSON',
data: formData,
success: function(value) {
if (value.msg == 'true') {
//your action
}else{
//your action
}
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
25473 次 |
最近记录: |