jquery and Ajax invoke Sina API to get short URL code

Source: Internet
Author: User
Tags button type json

  This article mainly introduces the call Sina API to get a short URL of a lot of methods, this example for you to use jquery and Ajax to achieve, the need for friends can refer to the following

  Code as follows: <!doctype html>  <html>  <head>  <meta charset= "Utf-8" >  < title> get Sina short URL </title>  <script src= "Http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js" > </script>  <!--<script type= "Text/javascript" src= "Js/jquery-2.1.0.min.js" ></script>-- >  </head>  <body>  <label for= "Long" > Long URL:</label>  <input value= " Http://baike.baidu.com/link?url=XLrVdYRThMvU_DlDT67v2wg9XYgG3xXvsB97WZFDz4psPORqGotkTiH1O5L1SGrD9Du-OSxWt_ 5E2KNTK01HHK "id=" Long ><br><br>  <label for= "App_key" > enter your app_key (no Internet search available): </label ><br>  <input value= "211160679" id= "App_key" ><br><br>  <span id= "Short" > Short URL:</span><br><br>  <span id= "Dlgcy" > Call address:</span><br><br>  <button type= "button" id= "BTN" >click me</button><br>  <!--<span id= "Link "> URL:</span>-->  <br><br><br>  <a href=" http://www.cnblogs.com/ azure/archive/2012/08/29/weiboapi.html "target=" _blank > Reference article: Take short chain service as an example, to explore the Appkey-free, authentication-free, Ajax Cross-domain call Sina Weibo api</a>   <br><br>  <a href= "http://open.weibo.com/tools/console?uri=short_url/shorten& Httpmethod=get&key1=url_long&value1=http%3a%2f%2fopen.weibo.com%2fqa "target=" _blank "> Sina API Test </a >  </body>    <script type= "Text/javascript" >  $ (document). Ready (function () {   $ ("#btn"). Click (function () {  var short = $ ("#short");  var long = $ ("#long"). Val ();//Get property value; //var url = "Https://api.weibo.com/2/short_url/shorten.json"; Official API address;  var url2 = "Http://api.weibo.com/2/short_url/shorten.json";  var App_key = $ ("#app_key"). Val (); /app_key invalidation may result in unresponsive; //var access_token; //var cmd = URL + "&url_long=" + Long + "&access_token=" + ACC ess_token;  var cmd2 = Url2 + "? source=" + App_key + "&url_long=" + long;    var message= "";  $.ajax ({//underlying method;  URL:CMD2,&NB Sp Type: "Get",  dataType: "Jsonp",///using the Jsonp method Ajax,json has cross-domain problems;  cache:false,  success:function (data, Status) { //Get returned information;  for (x in data.data.urls[0]) message + = x+ ' = ' +data.data.urls[0][x]+ ' & ';  alert ("data:n" + Message + "Nnstatus:" + status);  short.append (Data.data.urls[0].url_short + "<br>"); //$ (" #dlgcy "). Hide ();  $ (" #dlgcy "). Text (CMD2); },  error:function (obj,info,errobj) {  alert (" $.ajax Error occurred in (): "+ info"; } });   }); });  </script>  </html>    Code Download  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.