當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jQuery.ajax函數代碼示例

本文整理匯總了TypeScript中jQuery.ajax函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript ajax函數的具體用法?TypeScript ajax怎麽用?TypeScript ajax使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ajax函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: return

    return Rx.Observable.create( (observer:Rx.Observer<any>) => {

        let xhr = $.ajax({
                url: '/proxy/en.wikipedia.org/w/api.php',
                async:true,
                timeout: 1500,
                cache:false,
                data: {
                    action: 'opensearch',
                    format: 'json',
                    search: term
                },
                error: (jqXHR: JQueryXHR, textStatus: string, errorThrown: string) => {
                      //console.log( "error", textStatus, errorThrown);
                      observer.error( errorThrown );
                },
                success: (data: any, textStatus: string, jqXHR: JQueryXHR) => {
                    //console.log( "data", data);
                    observer.next( data );
                    observer.complete();
                }
          });
          return () => { // On Unsubscribe
            if( xhr!=null && !xhr.status) {
                xhr.abort();
                console.log( "canceled!" );    
            }

          }
    });
開發者ID:bsorrentino,項目名稱:rxjs-samples,代碼行數:30,代碼來源:autocomplete.ts

示例2: function

var updateTable = function() {
    $.ajax({
        url: "/peekLeaderboard",
        dataType: 'json'
    })
    .done(function(data) {
        let usernames = data.Usernames
        console.log(usernames)
        let scores = data.Scores
        let table = "<table id='leaderboard-table'>\
                      <thead>\
                        <tr>\
                          <th></th>\
                          <th>Name</th>\
                          <th>Score</th>\
                        </tr>\
                      </thead>"
        table += "<tbody>"
        for (var i = 0; i < 10; i++) {
            table += "<tr>\
            <td>" + (i + 1).toString() + "</td>"
         + "<td>" + usernames[i] + "</td>"
         + "<td>" + scores[i] + "</td></tr>"
        }
        table +=  "</tbody>"
        document.getElementById("leaderboardTable").innerHTML = table
    })
}
開發者ID:michaelRadigan,項目名稱:outgain,代碼行數:28,代碼來源:leaderboard.ts

示例3: fetchServerConfig

export function fetchServerConfig(){
    return $.ajax({
        url: getConfigurationServiceApiUrl(),
        dataType: "jsonp",
        jsonpCallback: "callback"
    });
}
開發者ID:agarwalrounak,項目名稱:cbioportal-frontend,代碼行數:7,代碼來源:config.ts

示例4: getImages

export function getImages(keyword) {
  let options: JQueryAjaxSettings = {
      url: `${CLIP_ART_ENDPOINT}?query=${keyword}&amount=20`
  };

  return $.ajax(options);
}
開發者ID:TienSFU25,項目名稱:graphical-memories,代碼行數:7,代碼來源:openClipartApi.ts

示例5: findFilesByName

 function findFilesByName(text, onComplete) {
    let originalText = text;
    
    if(text && text.length > 1) {
       $.ajax({
          url: '/file/' + Common.getProjectName() + '?expression=' + originalText,
          success: function (filesMatched) {
             var response = [];
             
             for(var i = 0; i < filesMatched.length; i++) {
                var fileMatch = filesMatched[i];
                var typeEntry = {
                   resource: fileMatch.resource,
                   path: fileMatch.path,
                   name: fileMatch.name,
                   project: Common.getProjectName()
                };
                response.push(fileMatch);
             }
             onComplete(response, originalText);
          },
          async: true
       });
    } else {
       onComplete([], originalText);
    }
 }
開發者ID:snapscript,項目名稱:snap-develop,代碼行數:27,代碼來源:commands.ts

示例6: fetchStaleVersionInfo

 private static fetchStaleVersionInfo() {
   return $.ajax({
     method: "GET",
     url: Routes.apiv1StaleVersionInfoPath(),
     beforeSend: mrequest.xhrConfig.forVersion("v1")
   });
 }
開發者ID:Skarlso,項目名稱:gocd,代碼行數:7,代碼來源:version_updater.ts

示例7: it

  it('should PUT', async () => {
    mock.use((req, res) => {
      expect(req.method()).to.eq('PUT');
      expect(String(req.url())).to.eq('/');
      expect(req.body()).to.eq(JSON.stringify({foo: 'bar'}));
      return res
        .status(200)
        .reason('OK')
        .header('Content-Length', '12')
        .body('Hello World!');
    });

    const res = await $.ajax({
      method: 'put',
      url: '/',
      data: JSON.stringify({foo: 'bar'})
    })
      .then((data, status, xhr) => {
        expect(xhr.status).to.eq(200);
        expect(xhr.statusText).to.eq('OK');
        expect(xhr.getAllResponseHeaders()).to.contain(
          'content-length: 12\r\n'
        );
        expect(data).to.eq('Hello World!');
      })
      .catch((xhr, status, error) => expect.fail(error));
  });
開發者ID:jameslnewell,項目名稱:xhr-mock,代碼行數:27,代碼來源:jquery.test.ts

示例8: save

	/**
	 * @memberof RegistrationController
	 * @this RegistrationController
	 * @instance
	 * @method save
	 * @desc Registers or updates the current device
	 */
	private save(): void {
		// Get the device details
		this.device.name = String($("#deviceName").val());

		// Send a PUT request to the server, including the device ID in the request headers
		$.ajax({
			url: `/devices/${this.device.name}`,
			context: this,
			type: "PUT",
			headers: {
				"X-DEVICE-ID": String(this.device.id)
			},
			success(_registrationReponse: string, _status: JQuery.Ajax.SuccessTextStatus, jqXHR: JQuery.jqXHR): void {
				// Get the device ID returned in the Location header
				this.device.id = jqXHR.getResponseHeader("Location");

				const device: Setting = new Setting("Device", JSON.stringify(this.device));

				// Update the database
				device.save();

				// Pop the view off the stack
				this.appController.popView();
			},
			error: (request: JQuery.jqXHR, statusText: JQuery.Ajax.ErrorTextStatus): void => this.appController.showNotice({
				label: `Registration failed: ${statusText}, ${request.status} (${request.statusText})`,
				leftButton: {
					style: "cautionButton",
					label: "OK"
				}
			})
		});
	}
開發者ID:scottohara,項目名稱:tvmanager,代碼行數:40,代碼來源:registration-controller.ts

示例9: showFileHistory

 export function showFileHistory() {
    var editorState: FileEditorState = FileEditor.currentEditorState();
    var editorPath: FilePath = editorState.getResource();
 
    if(!editorPath) {
       console.log("Editor path does not exist: ", editorState);
    }
    var resource = editorPath.getProjectPath();
    
    $.ajax({
       url: '/history/' + Common.getProjectName() + '/' + resource,
       success: function (currentRecords) {
          var historyRecords = [];
          var historyIndex = 1;
          
          for (var i = 0; i < currentRecords.length; i++) {
             var currentRecord = currentRecords[i];
             var recordResource: FilePath = FileTree.createResourcePath(currentRecord.path);
             
             historyRecords.push({ 
                recid: historyIndex++,
                resource: "<div class='historyPath'>" + recordResource.getFilePath() + "</div>", // /blah/file.snap 
                date: currentRecord.date,
                time: currentRecord.timeStamp,
                script: recordResource.getResourcePath() // /resource/<project>/blah/file.snap
             });
          }
          w2ui['history'].records = historyRecords;
          w2ui['history'].refresh();
       },
       async: true
    });
 }
開發者ID:snapscript,項目名稱:snap-develop,代碼行數:33,代碼來源:history.ts

示例10: unregister

	/**
	 * @memberof RegistrationController
	 * @this RegistrationController
	 * @instance
	 * @method unregister
	 * @desc Unregisters the current device
	 */
	private unregister(): void {
		// Send a DELETE request to the server
		$.ajax({
			url: `/devices/${this.device.id}`,
			context: this,
			type: "DELETE",
			headers: {
				"X-DEVICE-ID": String(this.device.id)
			},
			success(): void {
				const device: Setting = new Setting("Device", null);

				// Remove the device from the database
				device.remove();

				// Pop the view off the stack
				this.appController.popView();
			},
			error: (request: JQuery.jqXHR, statusText: JQuery.Ajax.ErrorTextStatus): void => this.appController.showNotice({
				label: `Unregister failed: ${statusText}, ${request.status} (${request.statusText})`,
				leftButton: {
					style: "cautionButton",
					label: "OK"
				}
			})
		});
	}
開發者ID:scottohara,項目名稱:tvmanager,代碼行數:34,代碼來源:registration-controller.ts


注:本文中的jQuery.ajax函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。