AJAX XMLHttpRequest POST [英] AJAX XMLHttpRequest POST

查看:30
本文介绍了AJAX XMLHttpRequest POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 POST 方法编写 XMLHttpRequest.我过去曾使用 GET 方法设法使用 XMLHttpRequest,但在使用 POST 时遇到了困难.

I'm trying to write an XMLHttpRequest using the POST method. I have managed to use XMLHttpRequest in the past using the GET method but am struggling with POST.

这是我的代码:

var xmlhttp = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

var url = "http://www.mysite.com/script.php";
var params = "var=1";
xmlhttp.open("POST", url, true);
xmlhttp.send(params);

它基本上调用一个 PHP 脚本,然后将一些信息添加到数据库中.

It basically calls a PHP script which then adds some information to a database.

推荐答案

好的,我已经整理好了.

Okay I've managed to sort it.

虽然奇怪,可能与沙箱安全相关,但我没有使用完整的 URL 地址,而是使用了文件的相对路径,现在它可以工作了.

Odd reason though, might be sandbox security related, but rather than have the full URL address, I have just used the relative path to the file, and now it works.

感谢大家的支持.

这篇关于AJAX XMLHttpRequest POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆