我试图通过$ .get()从php文件中获取URL值,这里是代码:
PHP文件夹名为' jquery_con4.php':
echo (isset($_GET['req'])) ? 'found':'notfound';
JQuery调用了#pass; js':
$.get('connection/jquery_con4.php', function(data){
alert(data);
});
名为' password_c.php'的主文件夹其中包括名为' pass.js'的javascript。它有$ .get但是它显示了我的注释' notfound',&如果删除了echo,则显示为' undefined index:req' ---网址是:' http://localhost/series/skyface/password_c.php?req=65yDq0zI39UcRSF'
谢谢!
答案 0 :(得分:0)
http://localhost:8888/series/skyface/password_c.php?req=65yDq0zI39UcRSF
为了将URL查询字符串中的'req'值传递给jquery_con4.php脚本,您需要一个JS函数来为您抓取它并将其传递给ajax请求。
下面是一个如何运作的例子。
/series/skyface/password_c.php
switch CLLocationManager.authorizationStatus() {
case .AuthorizedWhenInUse, .Restricted, .Denied:
let alertController = UIAlertController(
title: "Background Location Access Disabled",
message: "In order to be notified, please open this app's settings and set location access to 'Always'.",
preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
/main.js:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="../../main.js"></script>
</body>
</html>
/connection/jquery_con4.php:
jQuery(document).ready(function($) {
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function success(data) {
console.log(data);
}
$.ajax({
url: '/connection/jquery_con4.php',
data: {req : getParameterByName('req')},
success: success
});
});