Ajax呼叫Conrtoller返回資料

2022-03-25 19:39:30 字數 1759 閱讀 8443

前端ajax

function dorefund()

, datatype:'json',//返回資料型別為json型別

success: function (json) else

},error: function (json)

});後端controller中**:

public actionresult alibarpay(string strtradeno, string strauthcode, string

strtotalamount)

var vjson = new ;

return

json(vjson);//返回json型別

}

$.ajax(,

datatype: "text",//返回型別為string的

success: function (result)

$("#refunddetail").html(result);

alert(result);

}});

後端controller:

public actionresult alipayrefund(string strtradeno,string strproductid,string

strrefoundamount)

else

break

; }

return content(strresult);//

返回string型別

}

其中必須注意的是,如果是button來呼叫ajax,必須指定button的type='button',不然在ajax中不會返回值:

<

div>

<

span

>支付寶退費

span

>

<

form

>

<

span

>商戶訂單號:

span

><

input

type

="text"

name

="strtradeno3"

/>

<

span

>支付寶訂單號:

span

><

input

type

="text"

name

="strproductid"

/>

<

span

>總金額金額:

span

><

input

type

="text"

name

="strrefundamount"

/>

<

button

id="dosubmit4"

type

="button"

onclick

="dorefund()"

>退費提交

button

>//type='button' 必須寫,不然在方法中執行沒得返回值,但chrom中除錯可以顯示,不除錯時,就是顯示不出來!!!

form

>

<

span

id="refunddetail"

>

span

>

div>

ajax呼叫WCF服務

關於ajax呼叫wcf服務分為跨域和不跨域兩種方式,今天咱們先介紹下不跨域下的呼叫方法。demo是在vs2008寫的.經過測試與研究,發現ajax呼叫wcf服務必須滿足以下條件 1.wcf的通訊方式必須使用webhttpbinding 2.必須設定節點的值 3.服務的實現必須新增 aspnetcom...

Python Web 實現Ajax呼叫

html前端 python後端 class getmobilehandler web.requesthandler def get self id self.get argument id print id self.write 上面類繫結了 getmobile 注意以下幾點 1.html設定參考標...

jquery呼叫ajax方法

格式一 ajax 引數 type 請求方式get post url 請求位址url async 是否非同步,預設是true表示非同步 data 傳送到伺服器的資料 datatype 預期伺服器返回的資料型別 contenttype 設定請求頭 success 請求成功時呼叫此函式 error 請求失...