[英]How to pass data using jQuery/ Ajax to a URL
How to pass the fetched data using $.get() from a URL to a particular URL with query_string that can be retrieved using $_GET() in PHP. 如何使用$ .get()将获取的数据从URL传递到带有query_string的特定URL,可以在PHP中使用$ _GET()进行检索。 I'm using following but not working.
我正在使用关注但无法正常工作。 I want to pass the fetched data into following parameter http://example.com/data?data=FETECHED_DATA
我想将获取的数据传递到以下参数http://example.com/data?data=FETECHED_DATA
<?php
$ip_address=$_SERVER['REMOTE_ADDR'];
echo '<script>
$.get( "http://ipinfo.io/'.$ip_address.'/org", function( data ) {
$.ajax({
type: "GET",
url: "http://example.com/data",
data: data,
success: success,
dataType: dataType
});
});
</script>';?>
Well, don't recommended PHP to fetch and send data 好吧,不建议PHP获取和发送数据
I believe this will do what you want 我相信这会做你想要的
<?php
$ip_address=$_SERVER['REMOTE_ADDR'];
echo '<script>
$.get("http://ipinfo.io/'.$ip_address.'/org", function(data) {
$.ajax({
type: "GET",
url: "http://example.com/data",
data: {data : data},
success: success,
dataType: dataType
});
});
</script>';?>
the only change is data: data changed to data: {data: data} 唯一的变化是数据:数据已更改为数据:{data:data}
that's a lot of data :p 大量的数据:p
see this cut down mock up, http://jsfiddle.net/cm8o5dk8/ if you have a decent browser that can show you the network "usage" you'll see that the mockup fails trying to GET http://example.com/data?data=AS15169+Google+Inc.%0A
- the %0A comes back from ipinfo.io 如果您有一个不错的浏览器可以向您显示网络“使用情况”,请参阅此简化模型http://jsfiddle.net/cm8o5dk8/ ,您将看到该模型无法尝试获取
http://example.com/data?data=AS15169+Google+Inc.%0A
从ipinfo.io返回
Thanks it worked 谢谢工作
$.get("http://ipinfo.io/8.8.8.8/org", function(data) {
$.ajax({
type: "GET",
url: "http://example.com/data",
data: {data : data},
success: function() {},
dataType: 'json'
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.