2014-04-12 112 views
1

我试图将表单中的数据数据追加到请求中,以便完整的URL作为请求发送。我知道我可以在PHP中做到这一点,但想知道如果我也能做到这一点在例如JSON的请求被发送到将字符串附加到JavaScript中的JSON请求的末尾

"http://api.wunderground.com/api/myapi/conditions/q/ZIP.json" 

的JavaScript 凡ZIP将用户提交的被替换

$(function() { 
$("#getzip").submit(function() { 
    var zip_data =$(this).serialize(); 
    $.getJSON("get_weather.php",null , function(data); { 

可以通过它来代替null吗?我怎么会将其附加到严格的JavaScript请求?

回答

0

好像你就需要把它添加到URL字符串本身:

$.getJSON("http://api.wunderground.com/api/myapi/conditions/q/" 
+ zip_data, function(data){ return data }); 
0
$.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); 
相关问题