更新时间:2023-12-02 09:15:40
jQuery有一个很好的Ajax接口: /rel =nofollow> http://api.jquery.com/jQuery.ajax/
基本示例与您的网址类似在那里。它显示了如何覆盖MIME类型以及如何在请求从服务器返回数据时获取调用的函数。 API还提供错误功能和许多其他功能来以各种方式转换请求。
$ b url:http:// localhost:* / * / *,如果您想要将登录名和密码或任何其他数据发送到服务器,您也可以使用数据:...
字段。这可以将数据保存为来自表单的POST。
Consider the following ajax call:
function drawCharts() {
var jsonData1 = $.ajax({
url: "http://localhost:****/*/*",
dataType:"json",
async: false
}).responseText;
My index.html
<div id="chart_div" title='Speedo Information'></div>
I am making an api that converts json data to tabular form using Google Visualization Api.
While accessing the url alone the url asks for a user name and password. I have the credentials.
NOTE: The username and password is used to protect the data in the url from unauthorized access.
I need to ask for a user name while opening the index.html page and then display the table.
jQuery has an Ajax interface pretty well described here:
http://api.jquery.com/jQuery.ajax/
There basic example looks like this with your URL in there. It shows how to override the MIME type and how to get a function called once the request returns data from the server. The API also offers an error function and many other features to transform the request in various ways.
$.ajax({
url: "http://localhost:*/*/*",
beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
}
})
.done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data.slice( 0, 100 ) );
}
});
If you want to send the login and password or any other data to the server, you may also use the data: ...
field. That can hold data as in a POST from a form.