HTML5请求响应webservice [英] HTML5 request response webservice

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

问题描述

我是html5网站开发的新手

I am pretty new to html5 web development

我创建了一个包含登录名和密码的页面,并有一个提交按钮。
提交时,我向服务器发送一个休息请求,该服务器有一个网址

I have created a page with login and password on it and have a submit button. On submit , I send a rest request to the server which has a url

RRQUEST就像这样有点

THE RRQUEST IS SOMETHING LIKE THIS

<USERNAME>
abc
</USERNAME>
<PASSWORD>loooik
</PASSWORD>

在js文件中作为var data ...

which is in js file as var data...

此请求设置为

var parameters=JSON.stringify(data);

我使用以下代码建立连接

I use the following code for establishing connection

xmlHttp.open("post",url,true);
XmlHttp.setRequestHeader("Content-type","application/json);
xmlHttp.send(parameters);
xmlHttp.onreadystatechange=function X()
{
if(xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
return true;
}

我需要添加一个加载元素,并希望在请求和响应之间显示下一个屏幕。我实现了吗?

I need to add a loading element and want to display the next screen between request and the response. How can I achieve it?

在标签中我使用了提交输入类型,其中onClick属性调用返回sendPost()方法,该方法有要求被调用

In tag I have used submit input type where onClick attribute calls return sendPost() method which has the request to be called

我应该如何继续...加载屏幕并获得响应...假设下一个html屏幕上显示的名称

How should I proceed for the same... having loading screen and getting the response ... suppose just the name to be displayed on next html screen

推荐答案

首先看一下基本的jQuery示例。这将指导您了解jQuery的工作原理并在我将要提出的解决方案中提供大量帮助。

First of all see basic jQuery example. This will guide you through how jQuery works and help a lot in the solution I'm going to suggest.

http://learn.jquery.com/about-jquery/how-jquery-works/

jQuery拥有自己的AJAX方法和进一步的简写称为 $ .post

jQuery has it's own AJAX method and further shorthand called $.post

现在你可以写这样的东西 -

Now you can write something like this -

function requestNetwork() {
    // Code for loading screen
    $.ajax({
        url: "yourURL",
        data: "yourData"
    }).done(function(data) {
        alert(xmlHttp.responseText);
        // Code for dismissing loading screen
    }).fail(function(data) {
        // Code when call fails
    }).always(function() {
        // This code will always run
    });
}

这篇关于HTML5请求响应webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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