我正在尝试将表单中的数据附加到请求中,以便将完整的 URL 作为请求发送。我知道我可以在 PHP 中做到这一点,但想知道我是否也可以在 javascript 中做到这一点 例如json请求发送到
"http://api.wunderground.com/api/myapi/conditions/q/ZIP.json"
其中 ZIP 将被用户提交替换
$(function() {
$("#getzip").submit(function() {
var zip_data =$(this).serialize();
$.getJSON("get_weather.php",null , function(data); {
是否可以传递它来代替 null ?我该如何将其严格附加到 JavaScript 中的请求中?
最佳答案
$.getJSON("get_weather.php",{
whatever: "value",
somemore: "another value"
}.function(){
//
};
然后在你的 PHP 中:
$whatever=filter_input(INPUT_GET,"whatever",FILTER_SANITIZE_STRING);
$somemore=filter_input(INPUT_GET,"somemore",FILTER_SANITIZE_STRING);
关于javascript - 在 JavaScript 中将字符串附加到 JSON 请求的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23025078/