Tag: Ajax

使用AJAX,PHP和jQuery上传多个图像

我有很多问题使用AJAX上传多个图像。 我写这个代码: HTML <form id="upload" method="post" enctype="multipart/form-data"> <div id="drop" class="drop-area"> <div class="drop-area-label"> Drop image here </div> <input type="file" name="file" id="file" multiple/> </div> <ul class="gallery-image-list" id="uploads"> <!– The file uploads will be shown here –> </ul> </form> <div id="listTable"></div> jQuery的/ AJAX $(document).on("change", "input[name^='file']", function(e){ e.preventDefault(); var This = this, display = $("#uploads"); // list all file […]

使用ajax请求下载文件

我想发送一个“ajax下载请求”,当我点击一个button,所以我试图这样: JavaScript的: var xhr = new XMLHttpRequest(); xhr.open("GET", "download.php"); xhr.send(); 的download.php: <? header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename= file.txt"); header("Content-Transfer-Encoding: binary"); readfile("file.txt"); ?> 但不能按预期工作,我该怎么办? 先谢谢你

我怎么能添加一个自定义的HTTP头到js或jQuery的Ajax请求?

有谁知道如何使用JavaScript或jQuery添加或创build自定义HTTP标头?

停止jQuery .load被caching的响应

我有以下代码在URL上发出GET请求: $('#searchButton').click(function() { $('#inquiry').load('/portal/?f=searchBilling&pid=' + $('#query').val()); }); 但返回的结果并不总是反映出来。 例如,我改变了堆栈跟踪的响应,但是当我点击searchbutton时堆栈跟踪没有出现。 我查看了控制ajax响应的底层PHP代码,它有正确的代码,并直接访问页面显示正确的结果,但.load返回的输出是旧的。 如果我closures浏览器并重新打开它,它会工作一次,然后开始返回陈旧的信息。 我可以通过jQuery控制这个,或者我需要让我的PHP脚本输出头来控制caching?

jQuery的Ajaxerror handling,显示自定义的exception消息

有没有什么方法可以显示自定义exception消息作为我的jQuery AJAX错误消息中的警报? 例如,如果我想通过throw new ApplicationException("User name already exists");通过Struts在服务器端抛出exceptionthrow new ApplicationException("User name already exists"); ,我想在jQuery AJAX错误消息中捕获此消息(“用户名已存在”)。 jQuery("#save").click(function () { if (jQuery('#form').jVal()) { jQuery.ajax({ type: "POST", url: "saveuser.do", dataType: "html", data: "userId=" + encodeURIComponent(trim(document.forms[0].userId.value)), success: function (response) { jQuery("#usergrid").trigger("reloadGrid"); clear(); alert("Details saved successfully!!!"); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); } }); 在第二个提醒,我提醒抛出的错误,我越来越undefined […]

检测Internet连接是否脱机?

如何检测互联网连接在JavaScript中是离线的?

使用jQuery创build跨域ajax JSONP请求

我想parsingJSON数组与jquery ajax与下面的代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sample</title> <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script> <script type="text/javascript"> var result; function jsonparser1() { $.ajax({ type: "GET", url: "http://10.211.2.219:8080/SampleWebService/sample.do", dataType: "jsonp", success: function (xml) { alert(xml.data[0].city); result = xml.code; document.myform.result1.value = result; }, }); } </script> </head> <body> <p id="details"></p> <form name="myform"> <input type="button" name="clickme" […]

Ajax教程的post,并得到

我需要一个简单的Ajax教程或简单的input表单的案例研究,我想通过input表单发送一个用户名,该表单将其发送到数据库并回复结果。 任何build议这样的教程是受欢迎的,因为我只有一个使用Mootool,但我正在寻找一个使用jQuery!

如何用jQuery / JavaScriptparsingJSON数据?

我有一个AJAX调用返回一些像这样的JSON: $(document).ready(function () { $.ajax({ type: 'GET', url: 'http://example/functions.php', data: { get_param: 'value' }, success: function (data) { var names = data $('#cand').html(data); } }); }); #cand div里面我会得到: [ { "id" : "1", "name" : "test1" }, { "id" : "2", "name" : "test2" }, { "id" : "3", "name" : "test3" }, { "id" […]

如何将JSON对象转换为自定义C#对象?

有一种简单的方法来填充我的C#对象与通过AJAX传递的JSON对象? //这是使用JSON.stringify从页面传递给C#WEBMETHOD的JSON对象 { "user" : { "name" : "asdf", "teamname" : "b", "email" : "c", "players" : ["1", "2"] } } // C#WebMetod接收JSON对象 [WebMethod] public static void SaveTeam(Object user) { } // C#类,它表示传递给WebMethod的JSON对象的对象结构 public class User { public string name { get; set; } public string teamname { get; set; } public string email { […]