Tag: Ajax

使用新的URL更新地址栏而不散列或重新加载页面

我或者梦想铬(开发通道)实现一种方式来更新地址栏通过JavaScript(path,而不是域),无需重新加载页面,或他们真的已经做到了这一点。 但是,我找不到我认为我阅读的文章。 我疯了还是有办法做到这一点(在Chrome中)? PS我不是在谈论window.location.hash,等。 如果上述存在,这个问题的答案将是不真实的。

如何使用基本身份validation与jQuery和AJAX?

我试图通过浏览器创build一个基本的身份validation,但我不能真正到达那里。 如果这个脚本不在这里,那么浏览器authentication将会接pipe,但是我想告诉浏览器用户即将进行authentication。 地址应该是这样的: http://username:password@server.in.local/ 我有一个表单: <form name="cookieform" id="login" method="post"> <input type="text" name="username" id="username" class="text"/> <input type="password" name="password" id="password" class="text"/> <input type="submit" name="sub" value="Submit" class="page"/> </form> 和一个脚本: var username = $("input#username").val(); var password = $("input#password").val(); function make_base_auth(user, password) { var tok = user + ':' + password; var hash = Base64.encode(tok); return "Basic " + hash; […]

从JavaScript调用php函数

有没有一种方法可以通过JS函数运行一个PHP函数? 像这样的东西: <script type="text/javascript"> function test(){ document.getElementById("php_code").innerHTML="<?php query("hello"); ?>"; } </script> <a href="#" style="display:block; color:#000033; font-family:Tahoma; font-size:12px;" onclick="test(); return false;"> test </a> <span id="php_code"> </span> 我基本上想要运行PHP函数query("hello") ,当我点击名为“testing”,将调用PHP函数的HREF。

如何在jQuery中发送Ajax请求的FormData对象?

XMLHttpRequest Level 2标准(仍然是一个工作草案)定义了FormData接口。 这个接口可以将File对象附加到XHR请求(Ajax请求)。 顺便说一句,这是一个新的function – 过去,使用“隐藏的iframe技巧”(在我的其他问题阅读 )。 这是如何工作的(例子): var xhr = new XMLHttpRequest(), fd = new FormData(); fd.append( 'file', input.files[0] ); xhr.open( 'POST', 'http://example.com/script.php', true ); xhr.onreadystatechange = handler; xhr.send( fd ); 其中input是一个<input type="file">字段, handler是Ajax请求的成功处理程序。 这在所有浏览器(再次,除了IE浏览器)美丽的作品。 现在,我想使这个function与jQuery的工作。 我试过这个: var fd = new FormData(); fd.append( 'file', input.files[0] ); $.post( 'http://example.com/script.php', fd, handler ); 不幸的是,这是行不通的(一个“非法调用”的错误引发 – […]

PUT,DELETE,HEAD等方法在大多数Web浏览器中都可用?

我在这里看到了一些问题,比如如何debuggingREST风格的服务 ,其中提到: 不幸的是,相同的浏览器将不允许我testingHTTP PUT,DELETE,甚至在一定程度上甚至HTTP POST。 我也听说,浏览器只支持GET和POST,从一些其他来源,如: http://www.packetizer.com/ws/rest.html http://www.mail-archive.com/jmeter-user@jakarta.apache.org/msg13518.html http://www.xml.com/cs/user/view/cs_msg/1098 但是,Firefox中的一些快速testing显示,发送PUT和DELETE请求的方式正常 – XMLHttpRequest成功完成,请求以正确的方式显示在服务器日志中。 有没有这方面的一些方面,我缺less,如跨浏览器兼容性或非明显的限制?

等到所有的jQuery Ajax请求完成?

如何让一个函数等待,直到所有的jQuery Ajax请求在另一个函数内完成? 总之,在执行下一步之前,我需要等待所有的Ajax请求完成。 但是,如何?

如何返回AJAX响应文本?

我使用原型做我的AJAX开发,我使用这样的代码: somefunction: function(){ var result = ""; myAjax = new Ajax.Request(postUrl, { method: 'post', postBody: postData, contentType: 'application/x-www-form-urlencoded', onComplete: function(transport){ if (200 == transport.status) { result = transport.responseText; } } }); return result; } 我发现“结果”是一个空string。 所以,我试过这个: somefunction: function(){ var result = ""; myAjax = new Ajax.Request(postUrl, { method: 'post', postBody: postData, contentType: 'application/x-www-form-urlencoded', onComplete: function(transport){ […]

使用jQuery AJAX加载跨域端点

我试图加载使用AJAX的跨域HTML页面,但除非数据types是“jsonp”我无法得到响应。 然而,使用jsonp浏览器期待脚本MIMEtypes,但接收“文本/ HTML”。 我的请求代码是: $.ajax({ type: "GET", url: "http://saskatchewan.univ-ubs.fr:8080/SASStoredProcess/do?_username=DARTIES3-2012&_password=P@ssw0rd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute", dataType: "jsonp", }).success( function( data ) { $( 'div.ajax-field' ).html( data ); }); 有没有办法避免使用jsonp的请求? 我已经尝试使用crossDomain参数,但它没有工作。 如果不是有什么办法在jsonp中接收html内容? 目前控制台在jsonp回复中说“unexpected”。

使用XMLHttpRequest发送POST数据

我想在JavaScript中使用XMLHttpRequest发送一些数据。 假设我在HTML中有以下格式: <form name="inputform" action="somewhere" method="post"> <input type="hidden" value="person" name="user"> <input type="hidden" value="password" name="pwd"> <input type="hidden" value="place" name="organization"> <input type="hidden" value="key" name="requiredkey"> </form> 我怎样才能在JavaScript中使用XMLHttpRequest写等价物?

在jQuery中序列化为JSON

我需要序列化一个对象到JSON。 我正在使用jQuery。 有没有一个“标准”的方式来做到这一点? 我的具体情况:我有一个数组定义如下所示: var countries = new Array(); countries[0] = 'ga'; countries[1] = 'cd'; … 我需要把它变成一个string传递给$.ajax()像这样: $.ajax({ type: "POST", url: "Concessions.aspx/GetConcessions", data: "{'countries':['ga','cd']}", …