日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

js php调用webservice,js跨域调用WebService的使用方法

發(fā)布時(shí)間:2024/9/30 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 js php调用webservice,js跨域调用WebService的使用方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這次給大家?guī)韏s跨域調(diào)用WebService的使用方法,js跨域調(diào)用WebService的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。

步驟1. 在web.config中的system.web節(jié)點(diǎn)里加入

步驟2.webservice代碼using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Mvc;

namespace WebService

{

///

/// WebService1 的摘要說明

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。

[System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService

{

[ValidateInput(false)]

[WebMethod(Description = "測(cè)試")]

public void getDBTableInfos(string EnterpriseCode)

{

HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";

string jsonCallBackFunName = string.Empty;

jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();

HttpContext.Current.Response.Write(jsonCallBackFunName + "({ \"Result\": \"" + EnterpriseCode + "\" })");

}

}

}

步驟3.html頁面部分

Index

$(function () {

$("#btnSubmit").click(function () {

var EnterpriseCode = "39"; //企業(yè)代碼

var dataStr = "EnterpriseCode=" + EnterpriseCode;

$.ajax({

type: "get",

url: "http://xxx/xxx.asmx/AntiWebQuery_Ajax?jsoncallback?",

dataType: "jsonp",

jsonp: 'jsoncallback',

data: dataStr,

success: function (result) {

//返回結(jié)果

alert(result.Result);

}

});

});

});

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!

推薦閱讀:

總結(jié)

以上是生活随笔為你收集整理的js php调用webservice,js跨域调用WebService的使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。