Tag: rest

如何强制jqgrid使用查询字符串中的OData查询数据

免费的jqgrid使用读取远程json数据 $.jgrid.useJSON = true; $.extend(true, $.jgrid.defaults, { mtype: ‘GET’, url: ‘@Html.Raw(Url.Action(“Entity”, “API”,))’ } ); 搜索窗口是使用定义的 $.extend(true, $.jgrid.search, { multipleSearch: true, recreateFilter: true, closeAfterSearch: true, overlay: 0, recreateForm: true }); 如果按下搜索按钮,则会创建丑陋的filter查询字符串参数 http://localhost:52216/admin/API/Entity/DoklstlG?search=true&nd=1448746804617&rows=20&page=1&sidx=customer&_sord=desc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22Klient_nimi%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22a%22%7D%5D%7D 如何更改此url,尤其是以OData格式生成的filters子句? 我阅读了jqgrid OData插件wiki文章,但还没有找到这种可能性。

如何通过uploadcare中的rest api删除文件

我正在尝试使用jquery ajax删除uploadcare rest api中的文件。 这是我目前的jquery代码: $.ajax({ url: “http://api.uploadcare.com/files/” + $(“#photoguid”).val() + “/”, type: “DELETE”, contentType: “application/json” }); 我的问题是如何正确实现它,因为每次我调用它,它都会将我重定向到登录页面,这就是我在查看提琴手时看到的内容,我不知道在哪里放置授权。 我只是为此使用免费试用版。

JQuery Ajax基本身份validation标头无法正常工作

我试图在JQuery中的服务器上发出一个简单的GET请求。 $.ajax({ headers: { “Authorization”: “Basic ” + btoa(“hello” + “:” + “world”) }, url: “http://hello.world?Id=1”, method: “GET”, success: function () { }, }).then(function () { }); 问题是,当发送请求时,身份validation标头未正确放入请求中: Host: hello.world User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: de,en-US;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate Access-Control-Request-Method: GET Access-Control-Request-Headers: authorization Origin: null Connection: keep-alive Cache-Control: […]

415尝试在Jax-RSjersey中发送FormData()时的状态

我正在尝试使用jquery ajax发送附加到FormData的文件。 在介绍了一些mozilla和IBM的文档之后,我想出了以下内容。 ajax代码: var sessionId = $.cookie(“referenceId”); var myFormData = { sessionId: sessionId, cipherData: cipherData, // Encrypted xml data payslip: document.getElementById(‘payslip’).files[0]}; var formData = new FormData(); for (var key in myFormData) { console.log(key, myFormData[key]); formData.append(key, myFormData[key]); } $.ajax({ url : ‘api/rootpath/childpath’, type : ‘POST’, processData: false, contentType: false, // Here the contentType is set […]

Gmail REST API – 将邮件标记为已读

我正在尝试使用Gmail REST API将邮件标记为已读。 $(‘#markGmailRead’).click(function(){ var request = $.ajax({ type: ‘POST’, dataType: ‘json’, headers: { “Authorization”: “Bearer <>”, “Content-Type”: “application/json”}, url: ‘https://www.googleapis.com/gmail/v1/users/me/messages/<>/modify’, data: {“addLabelIds”: [“UNREAD”]} }) request.done(function(data){ // when the Deferred is resolved. console.log(data); }) request.fail(function(){ // when the Deferred is rejected. console.log(‘fail’); }) }) 这导致返回以下json: { “error”: { “errors”: [ { “domain”: “global”, “reason”: “parseError”, […]

Spring RESTful ajax会出错

当我将服务地址http://localhost:8080/mailservice/mail/name放入Web浏览器地址栏时,我会收到json中的响应,如下所示: [“name”] 但是当我创建一个像这样的简单的html页面时: $( document ).ready(function() { doMagic(); }); function doMagic() { $.ajax({ type: ‘GET’, url: ‘http://localhost:8080/mailservice/mail/name’, contentType:”application/json”, success: function () { console.log(“ok”); }, error: function (request, status, error) { console.log(status); } }); } 我的ajax总是遇到错误函数,如果我使用POST(不同的ajax代码与html,此处不存在)或GET,则无关紧要。 我的控制器看起来像这样: @Controller @RequestMapping(“/mail”) public class MailController { @Autowired MailService mailService; @RequestMapping(value = “/{name}”, method = RequestMethod.GET, produces={“application/json”}) public @ResponseBody List […]

JQuery的Ajax函数在chrome中运行,但在firefox中返回404

我正在使用中央ajax函数将ajax Post请求发送到服务器。 这是函数的代码: function postJson(url, jsObj, whenSuccess, whenError){ $.ajax({ type: “post”, headers: { “Accept”: “application/json, text/javascript, */*; q=0.01”, “Content-Type”: “application/json, text/javascript, */*; q=0.01” }, dataType: “json”, url: url, data: JSON.stringify(jsObj), success: function(result){ if(whenSuccess !== undefined){ whenSuccess(result); } }, error: function(xhr){ if(whenError !== undefined){ whenError(xhr.status); } } }); } 当我尝试运行我的应用程序时,它在chrome中工作正常,但在firefox中它会抛出404.当接受或内容类型未设置为JSON时,我的REST服务助手返回404 …所以我认为firefox可能不会添加标题但是当我查看发送的请求时: Request URL: http://localhost:9081/api/1/localize/validation.json Request Method: […]

net.sf.json.JSONException:Struts 2中的层次结构中有一个循环

我正在使用实现ModelDriven Struts类。 我能够从jQuery传递数据并将数据保存在数据库中。 当我尝试检索数据并将其传递回jQuery时,我不确定为什么它在jQuery中不可用。 我确信我错过了基本流程的东西.. 这是我的动作课。 public HttpHeaders index() { model = projectService.getProjectDetails(project.getUserID()); return new DefaultHttpHeaders(“success”).setLocationId(“”); } @Override public Object getModel() { return project; } public Project getProject() { return project; } public void setProject(Project project) { this.project = project; } 这是我的jQuery function getProjectDetails() { var userID = localStorage.getItem(‘userID’); var request = $.ajax({ url : […]

如何在ASP.Net中发送用于Web请求集的身份validation标头

我正在开发ASP.net应用程序,它使用ASP.Net Web API来使用REST服务。 我正在尝试为我的网站使用基本身份validation。 完成基本身份validation后,我计划将其与SSL一起使用。 目前在登录按钮上单击我正在使用用户名和密码的Base64编码发送Auth标头,如下所示: string responseData = string.Empty; string authToken = string.Empty; string loginInstance = url; // Create request. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginInstance); request.Method = “POST”; request.ContentType = “application/json”; request.CookieContainer = new CookieContainer(); String username = txtUserName.Text; String password = txtPassword.Text; String encoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + “:” + password)); request.Headers.Add(“Authorization”, “Basic ” + […]

Java RESTful服务的Jquery调用不工作CORS

我在Tomcat 7上部署了一个rest服务并正在运行。 我可以通过浏览器获取响应数据,但是当我通过jQuery尝试它时,它显示错误。 请检查快照。 @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpRes = (HttpServletResponse) res; //System.out.println(“Client Ip is : “+ SecurityFilter.getClientIpAddr(httpReq)); String domain = new URL(httpReq.getRequestURL().toString()).getHost(); //System.out.println(“Domain is ” + domain); // referrer String referrer = httpReq.getHeader(“referer”); //System.out.println(“Referral URL is -” + referrer); […]