我有一个客户端应用程序,它通过 AJAX POST 请求 ( request.open("POST", url, flag)) 向我的 Perl CGI 脚本提交一些数据。
如何使用 Perl 检索此数据并返回一些其他数据(AJAX 响应)?
我有一个文本区域:
<textarea id="my_text"></textarea>
Run Code Online (Sandbox Code Playgroud)
并在 javascript 中有一些 ajax 代码,如下所示:
var xmlhttp = new XMLHttpRequest();
var my_text = document.getElementById("my_text").value;
xmlhttp.open("POST", ".", true);
xmlhttp.send("my_text=" + my_text + "&foo=1");
Run Code Online (Sandbox Code Playgroud)
当我用 string 填充 textareaabc +1 +2 +3并运行 JS 代码时。我在服务器端得到的“my_text”的值是abc 1 2 3。
如何更改 JS 代码以abc +1 +2 +3在服务器端获取正确的字符串。
我正在编写一个脚本,它将改变人们在线程内查看 4chan 的方式,并添加一些功能。
在 4chan 线程中,当您上传图像时,服务器将生成与原始文件同名的缩略图,并保存该图像以供人们查看,但名称为 unix 时间戳。当您单击缩略图时,它src会更改为其父级的href,这意味着图像的名称只是时间戳,根本不是一个有用的名称。
这有两个问题
在此 SO 答案中,您可以看到唯一能够处理所有类型文件(我应该能够加载 jpg、png、gif 和 webm)的无损方法是对服务器进行查询,请求文件,读取它并将其转换为数据 URI。当图像缓存在src属性内时,我可以(根据此 SO 答案)简单地添加download具有原始文件名的属性,我的两点将得到解决。
我使用Chrome 扩展Styler将以下脚本注入到 4chan 中。
$(function(){
if ($('body').hasClass('is_thread')) {
$.getScript("http://my.url/updater.js").done(function() {
$('html').addClass('done')
}).fail(function() {
$('html').addClass('done failed')
})
}
})
Run Code Online (Sandbox Code Playgroud)
然后,我的 url 处的脚本将加载到文档本身中,并从那里开始执行自己的操作(我计划与某些人共享代码,这就是我(暂时)将脚本放在服务器上的原因)。
脚本内部有一个部分会循环所有新帖子并尝试再次请求该文件。
var $media = $post.find('img, video')
if ($media.length) {
$.ajax({
url: $media.parent().attr('href'),
method: 'GET',
success: function (data) {
console.log(data)
},
error: …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序可以将此脚本标签添加到商店中。
过去,我使用此脚本的脚本标签来监视客户的购物车活动。当脚本标签检测到 XHR 时,它会将一些数据发送到我的后端。
var oldXHR = window.XMLHttpRequest;
function newXHR() {
console.log('XHR detected!')
var realXHR = new oldXHR();
realXHR.addEventListener(
"load",
function () {
if (realXHR.readyState == 4 && realXHR.status == 200) {
if (realXHR._url === "/cart.js" || realXHR._url === "/cart/change.js") {
// do something....
}
}
},
false
);
return realXHR;
}
window.XMLHttpRequest = newXHR;
Run Code Online (Sandbox Code Playgroud)
但今天我不知道为什么更改购物车和将商品添加到购物车的操作无法再触发 XHR 侦听器。然而,这个脚本标签在我的旧商店中仍然有效。但如果我将其安装到新商店,它不会触发任何内容。我检查脚本标签是否在该新存储中正常运行,但问题是 XHR 侦听器未触发。
有人有一些想法吗?
我有
enter code here
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser is too old to run me!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = …Run Code Online (Sandbox Code Playgroud) 我在Google Play上有一个PNR查询应用程序.它工作得非常好.但最近Indian Railwys在他们的PNR查询部分添加了验证码,因此我无法将适当的数据传递给服务器以获得适当的响应.如何在我的应用程序中以imageview的形式添加此验证码,并要求用户输入验证码详细信息,以便我可以发送正确的数据并获得适当的响应.
这是我之前使用的PnrCheck.java.请帮助在这里做什么修改..
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.DefaultHttpClientConnection;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.util.EntityUtils;
public class PNRStatusCheck {
public static void main(String args[]) {
try {
String pnr1 = …Run Code Online (Sandbox Code Playgroud) 我的ajax功能每15秒工作一次.我想在2分钟后停止它.
我怎样才能做到这一点?
window.setInterval(function () {
var request = $.ajax({
...
})
}, 15000);
Run Code Online (Sandbox Code Playgroud) 我使用以下代码在小工具中获取Google:
<html>
<head>
<title>Browser</title>
</head>
<body onload= "getListCollection()" style="width:900px; height:900px;" >
<div id="listAttributes" style="width:400px; height:400px;" ></div>
<script>
function getListCollection() {
var url = "https://www.google.co.uk"
xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET',url,true, 'user', 'password');
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4);
{
document.getElementById("listAttributes").innerHTML = xmlhttp.responseText
}
}
xmlhttp.send(null);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用$ ajax做同样的事情?
我看了不同的例子,但我不知道他们将如何适应这种情况.或者,如果你可以发布一些不错的$ ajax教程.
当我将其更改为此时,它不起作用:
<html>
<head>
<title>Browser</title>
</head>
<body onload= "getListCollection()" style="width:900px; height:900px;" >
<div id="listAttributes" style="width:400px; height:400px;" ></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
$.ajax({
url : 'https://www.google.co.uk',
type : 'GET',
success : …Run Code Online (Sandbox Code Playgroud)