[英]Ajax query not working from server in asp.net mvc3
我已經開發了一個asp.net mvc3應用程序。 將有一個初始視圖,該視圖搜索客戶列表並加載另一個視圖。 我通過ajax $ .get函數來執行此操作。 在我的本地機器上運行正常。 但是,這在服務器實例中不起作用。 也沒有錯誤消息。
碼:
SearchCust.cshtml:
@model fbpm.Models.UserDetail
@{
ViewBag.Title = "Customer List";
}
<h2>Search for a Customer</h2>
Customer ID : <input type="text" id="cust" name="cust"/>
<button class="btn btn-primary btn-large" type="button" onclick="handlesearch();"> Search </button>
<br />
<br />
<div id='custlist'> Enter the Customer ID in the above field and click Search </div>
<script type="text/javascript" language="javascript">
$.get('@Url.Action("Index", "User")?id=' + document.getElementById("cust").value,
function (viewResult) {
$("#custlist").html(viewResult);
});
function handlesearch() {
$.get('@Url.Action("Index", "User")?id=' + document.getElementById("cust").value,
function (viewResult) {
$("#custlist").html(viewResult);
});
}
</script>
代碼:index.cshtml:
@model IEnumerable<fbpm.Models.UserDetail>
@{
Layout = null;
}
<h2>List of Customers</h2>
<button type="button" name="CreateUser" onclick="createuser();"> Create Customer </button>
<table>
<tr>
<th>
User ID
</th>
<th>
Password
</th>
<th>
Customer Name
</th>
<th>
Email ID
</th>
<th>
Contact #1
</th>
<th>
Contact #2
</th>
<th>
Complete Address
</th>
<th>
State
</th>
<th>
Country
</th>
<th>
Role
</th>
<th>
PAN Number
</th>
<th>
Project Name
</th>
<th>
Booked Date
</th>
<th>
Booked Amount
</th>
<th></th>
</tr>
@foreach (var item in Model) {
if (@Html.DisplayFor(modelItem => item.Role).ToString().Equals("400"))
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Password)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmailID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Contact1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Contact2)
</td>
<td>
@Html.DisplayFor(modelItem => item.FullAddress)
</td>
<td>
@Html.DisplayFor(modelItem => item.State)
</td>
<td>
@Html.DisplayFor(modelItem => item.Country)
</td>
<td>
@Html.DisplayFor(modelItem => item.Role)
</td>
<td>
@Html.DisplayFor(modelItem => item.PANNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProjectName)
</td>
<td>
@Html.DisplayFor(modelItem => item.BookedDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.BookedAmount)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = @Html.DisplayFor(modelItem => item.UserID) }) |
@Html.ActionLink("Details", "Details", new { id = @Html.DisplayFor(modelItem => item.UserID) }) |
@Html.ActionLink("Delete", "Delete", new { id = @Html.DisplayFor(modelItem => item.UserID) })
</td>
</tr>
}
}
</table>
<script type="text/javascript" language="javascript">
function createuser() {
var url = '@Url.Action("Create")';
window.location.href = url;
}
</script>
現在,此操作的類為:
public ViewResult SearchCust() {
return View();
}
public ViewResult Index(string id)
{
var cust = db.UserDetails.Where(c => c.UserID.Contains(id));
return View(cust.ToList());
}
我的瀏覽器給出了錯誤:它給出了錯誤“ ReferenceError:jQuery未定義”。。不確定我在這里應該做什么。 我在腳本文件中有jquery 1.9.1 min甚至1.8。
請有人能幫我解決為什么沒有打這個電話嗎?
問候,哈里
由於您的評論,請確保在標記之后立即將jQuery庫作為第一個加載的腳本。 通過瀏覽器確認它實際上也已加載。
<body>
<!--your mark-up-->
<!--jQuery script: either local file or from CDN (jQuery before jQuery UI)-->
<!--rest of your scripts, putting the scripts that-->
<!--are depended on in other scripts first-->
</body>
*終於可以了!! :)我要做的就是只是調用jquery src文件,並將用戶帳戶添加到數據庫中!
謝謝你們。 *
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.