Ext is not definied in ext.net mvc - wcf

Currently, I am start to use ext.net mvc. So, everything is new for me. Please help me for it. It is showing ext is not defined. I think that it is missing some js file.I created Indext.cshtml and code as below:
Thank you in advance.
#{
ViewBag.Title = "Index";
}
<script>
Ext.onReady(function () {
alert('start');
var myparams1 = new Object();
myparams1.id = 1;
Ext.Ajax.request({
url: 'Services/AService.svc/GetMyData'
method: 'GET',
success: function (response, options) {
// response callback
alert('Success');
},
failure: function (response, options) {
Ext.MessageBox.alert('Failed', 'Unable to get');
}
});
});
</script>

I just found the link.We can link ext-base and ext-all in cshtml.
<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/tags/ext-2.2/release/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="http://extjs-public.googlecode.com/svn/tags/ext-2.2/release/ext-all.js"></script>

Related

Send string from asp.net core controller to ajax in ajax call response

hi I'm trying to send a string from controller to ajax in ajax call response. but my ajax doesn't get the string in response , and i see the raw content in browser.Actually ,this is a simple example of my main project.
I'm using ASP.NET Core for server side programming.
here's my codes:
server side :
public IActionResult addlink(string link)
{
return Redirect("/home/showlink?key=" + link);
}
public IActionResult showlink(string key)
{
return Content("this is content from 2nd controller");
}
client side :
<form>
<input type="text" id="mainlink"/>
<button id="btn">submit</button>
</form>
<script>
$("#btn").click(function () {
$.ajax({
type: "POST",
url: "/home/addlink",
data: {
"link": $("#mainlink").val()
},
success: function (response) {
alert(response);
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
}
)
})
</script>
what i see in browser :
in main project i want to send a text from controller to ajax call succes ,just this, please help me :)
Try to return Ok ActionResult:
public IActionResult addlink(string link)
{
return Ok("/home/showlink?key=" + link);
}
If you add ajax to the submit button in the form, you should prevent the default behavior of form submission.
<script>
$("#btn").click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/home/addlink",
data: {
"link": $("#mainlink").val()
},
success: function (response) {
alert(response);
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
}
)
})
</script>

I want to delete a post (data) from the database and got this error `Uncaught ReferenceError: $ is not defined`

I have these in my layout.ejs
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
My main.js file
$(document).ready(function() {
$('.delete-article').on('click', function(e) {
$target = $(e.target);
const id = $target.atrr('data-id');
$.ajax({
type: 'DELETE',
url: '/post/'+id,
success: function(response) {
alert('Deleting Post');
window.location.href='/';
},
error: function(err){
console.log(err);
}
})
})
})
and these is my delete link
<a class="delete-article" href="#" data-id="{item._id}">Delete</a>
I have installed jQuery
npm install jquery
index.js file
router.delete( '/post/:id', function( req, res ){
let query = {_id:req.params.id}
Post.remove(query, function(err) {
if(err){
console.log(err);
}
res.send('Success');
});
});
I am getting the error main.js:1 Uncaught ReferenceError: $ is not defined whenever I refresh my browser without even clicking on delete link.
I know this is a problem from jQuery but I decided to post all my codes to make it easier for someone to help. I started learning Nodejs and Express one month ago.

How to update webrtc xirsys from v2 to v3?

I am currently testing and working on the webrtc firebase demo by Muaz khan. In one of the files it uses Xirsys and the credentials used are the ones of Muaz Khan. The xirsys details are of version v2. Currently Xirsys uses version V3. I was wondering how to change the former code to the new code.
The former code which is working in the demo is
<script type="text/javascript" src="https://gc.kis.v2.scr.kaspersky-
labs.com/EC7AD6FB-B1E9-9D47-B085-7DB58B77DF98/main.js" charset="UTF-8">
</script><script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var url = 'https://service.xirsys.com/ice';
var xhr = createCORSRequest('POST', url);
xhr.onload = function () {
window.parent.postMessage({
iceServers: JSON.parse(xhr.responseText).d.iceServers
}, '*');
};
xhr.onerror = function () {
console.error('Woops, there was an error making xhr request.');
};
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
window.addEventListener('message', function (event) {
if (!event.data || typeof event.data !== 'string') return;
if(event.data == 'get-ice-servers') {
xhr.send('ident=muazkh&secret=59d93f26-5b89-11e5-babe-
d61aeb366a63&domain=webrtcexperiment-webrtc.netdna-
ssl.com&application=default&room=default&secure=1');
}
});
</script>
According to the new Xirsys documentation it should be like
<!-- JS Get ICE STUN and TURN list -->
<DOCTYPE>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js">
</script>
<script>
$( document ).ready( function () {
$.ajax ({
url: "https://global.xirsys.net/_turn/muazkh/",
type: "PUT",
async: false,
headers: {
"Authorization": "Basic " + btoa("muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63")
},
success: function (res){
console.log("ICE List: "+res.v.iceServers);
}
});
})
</script>
</head>
<body>
</body>
</html>
What I did was this but did not work
<head><script>
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var url = 'https://global.xirsys.net/_turn/muazkh/default/default';
var xhr = createCORSRequest('PUT', url);
xhr.onload = function () {
window.parent.postMessage({
iceServers: JSON.parse(xhr.responseText).v.iceServers
}, '*');
};
xhr.onerror = function () {
console.error('Woops, there was an error making xhr request.');
};
xhr.setRequestHeader("Authorization", "muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63");
window.addEventListener('message', function (event) {
if (!event.data || typeof event.data !== 'string') return;
if(event.data == 'get-ice-servers') {
xhr.send();
}
});
</script>
</head>
Will greatly appreciate any help here. Thanks
Looks like a headers issue. The authorization header should use the "Basic" authentication scheme.
Please change your XMLHttpRequest's "setRequestHeader" to:
xhr.setRequestHeader("Authorization", "Basic "+ btoa("muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63") );

Bootstrap multiselect refresh or rebuild does not work

I want to bind my multiselect with ajax but after ajax call items does not show.I try rebuild or refresh multiselect but it still does not show
<script type="text/javascript">
$(document).ready(function () {
var categCheck = $('#multiselect').multiselect({
includeSelectAllOption: true,
enableFiltering: true
});
$.ajax({
type: 'GET',
url: "#Url.Content("~/Home/Listpositions/")",
success: function (data) {
$.each(data.data, function (index, item) {
alert(item.PositionName);
var opt = $('<option />', {
value: item.PID,
text: item.PositionName
});
opt.appendTo(categCheck);
});
}
});
$('#multiselect').multiselect('rebuild');
categCheck.multiselect('rebuild');
categCheck.multiselect('refresh');
$("select.multiselect").multiselect("refresh");
});
</script>
Here is my multiSelect page link:http://pratikisara.com/Home/Quick
How can I make ajax call from multiselect JS file(enter link description here) and in which code block should I do ajax call?
You need to to the rebuild and/or refresh in the AJAX success function. In your code, the AJAX call is made, then the multiselect is rebuild. But the rebuilt may happen before the AJAX call succeeds. Try this:
<script type="text/javascript">
$(document).ready(function () {
var categCheck = $('#multiselect').multiselect({
includeSelectAllOption: true,
enableFiltering: true
});
$.ajax({
type: 'GET',
url: "#Url.Content("~/Home/Listpositions/")",
success: function (data) {
$.each(data.data, function (index, item) {
alert(item.PositionName);
var opt = $('<option />', {
value: item.PID,
text: item.PositionName
});
opt.appendTo(categCheck);
// Rebuild after adding the options!
$('#multiselect').multiselect('rebuild');
});
}
});
});
</script>
by using reload its working fine for me. multiselect("reload") function refresh checkbox list in ajax call.
var obj_ddl_ExistingIdea = $("#ddl_ExistingIdea");
if (response.length > 0) {
for (var i = 0; i < response.length; i++) {
var str_newOption = '';
str_newOption = "<option value='" + response[i].IdeabookId + "'>" + response[i].Name + "</option>";
obj_ddl_ExistingIdea.append(str_newOption);
}
obj_ddl_ExistingIdea.multiselect("reload"); //using reload its working for me
$('#sltHeadCountdetailsCategorySiteCode').empty();
$("#sltHeadCountdetailsCategorySiteCode").multiselect('destroy');
This Is 100% fine code....
$(document).ready(function() {
var chkreport = $('#reporting_unit'); // Object creation for your dropdown
var ajaxpath = 'ajax/fend.php';
var ajaxUrl = baseUrl + ajaxpath;
$('#hospital_category').on('change', function() {
var hospital_id = this.value;
//alert(hospital_id);
$.ajax({
method: 'POST',
url: ajaxUrl,
data: {
perform_action: 'reporting_list',
hospital_id: hospital_id
},
dataType: 'html',
success: function(result) {
chkreport.append(result); // append option in the object created before ajax calling
// Now call multiselect function with their parameter
chkreport.multiselect({
columns: 1,
placeholder: 'Select Reporting Unit',
search: true,
selectAll: true
});
chkreport.multiselect('rebuild'); // it will reload dropdown need to create multiselect with checkbox option.
}
});
});
});

How to post viewbag values to post methos using ajax jquery in mvc 4?

I am retrieving my list of values in ViewBag and I am displaying ViewBag values in adropdownlist, but I am unable to post the dropdownlist values in HttpPost action. If I am using button values are passing to HttpPost action, ajax jquery not passing values. Please help me
<script type="text/javascript">
$(document).ready(function () {
$("#refresh").change(function (e) {
$.ajax({
type: "POST",
url: '#Url.Action("update", "Home")',
});
e.preventDefault();
});
});
</script>
#using (Html.BeginForm())
{
for (int i = 0; i < Model.Count(); i++)
{
#Html.DropDownList("StateType", ViewBag.StateType as SelectList, new { #id = "refresh" })
}
}
[HttpPost] ///values are not passing here
public ActionResult update(FormCollection FC)
{
}
This is how it should works:
First Controller:
public ActionResult Index()
{
// put data into Viewbag
ViewBag.StateType = methodThatReturnsSelectList();
return View();
}
Index.cshtml is used because View() has no parameter and the controller's name is Index.
#using (Html.BeginForm())
{
for (int i = 0; i < Model.Count(); i++)
{
#Html.DropDownList("StateType", ViewBag.StateType as SelectList, new { #id = "refresh" })
}
<script type="text/javascript">
$(document).ready(function () {
$("#refresh").change(function (e) {
$.ajax(
{
type: "POST",
url: '#Url.Action("update", "Home")',
data: $( "#myselect" ).val();
});
e.preventDefault();
});
});
</script>
This AJAX Call make a POST request to the controller HOME and action Update (second controller), and give the value of the myselect id, so in the controller you catch it:
[HTTPOST]
public ActionResult Update(string value)
{
// doing stuff
}
I think it will clarify how to do and it will helps you.