我正在使用OutBrain API,我試圖從服務器獲取一些數據。Asp.net - 按鈕不起作用
我做了一個簡單的HTML頁面,只需要營銷人員ID並返回他的名字。
當我點擊按鈕 - 什麼都沒有發生。有人能告訴我我的問題是什麼嗎?
我正在使用visual studio 2013並使用MVC ASP.NET。
謝謝!
代碼:
index.cshtml
@{
ViewBag.Title = "Home Page";
}
<br />
<div class="details">
<label>Enter Marketer ID</label>
<input type="text" class="form-control" id="marketerID">
<button type="button" class="btn btn-default" id="buttonB">OK</button>
<section class="details">
<div class="name">
<label>Name</label>
<label id="nameMarketer"></label>
</div>
</section>
</div>
<script src="~/Scripts/outBrain.js"></script>
outBrain.js
$("#buttonB").on('click', function() {
function getMarketer()
{
$.ajax(
{
url: "/home/GetOutBrainMarketers",
data: { id: $("marketerID").val() },
success: function (result) {
var marketer = JSON.parse(result);
document.getElementById("nameMarketer").innerHTML = (marketer.name);
}
}
)
}
});
HomeController.cs
namespace OutBrain_test.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
public async Task<string> GetOutBrainMarketers(string ID)
{
var baseAddress = new Uri("https://api.outbrain.com/amplify/v0.1/marketers/" + ID);
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("OB-TOKEN-V1", AuthorizeOutBrain().Result);
using (var response = await httpClient.GetAsync("marketers/"+ ID))
{
string responseData = await response.Content.ReadAsStringAsync();
return responseData;
}
}
}
public async Task<string> AuthorizeOutBrain()
{
var baseAddress = new Uri("https://api.outbrain.com/amplify/v0.1/login");
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "BASIC BASE-64-ENC(my-username:my-pass)");
using (var response = await httpClient.GetAsync("login"))
{
string responseData = await response.Content.ReadAsStringAsync();
return responseData;
}
}
}
}
}
你爲什麼換''按功能getMarketer' $ .ajax'?這是什麼意思? –
好的,好的,也許這就是我的問題,但多數民衆贊成在嗎? – Tal
嘗試打開它並再次單擊。 –