When I run the application in IIS, it stucks in Home controller and doesn't continue to the next controller(Data controller) as I wrote in the URL. When I run this in debug mode, it works, not in IIS. How can I fix it?
<script type="text/javascript">
alert('1');
$(document).ready(setInterval(function () {
$.ajax({
url: '/api/data/',
data: { pcName: '' },
type: 'GET',
success: function (CLID) {
//
if (CLID != null) {
$.ajax({
data: { line: CLID },
type: 'POST',
datatype: 'html',
url: '/Home/PopPage/',
success: function (data) {
var w = window.open("about:blank", 'PopPage', 'height=300,width=200');
$(w.document.body).html(data.toString());
}
});
}
}
});
}, 2000));
</script>
Try the razor syntax for creating URL
url : '#Url.Content("~/api/controllername/actionname")'
url : '#Url.Content("~/Home/PopPage")'
OR
url: '#Url.Action("PopPage", "Home")'
because, after hosting, you need to consider the Application name given in the iis. This could be an issue
Related
function name does not exist in the current context is the error it gives me. I want a dynamic ajax call. Why does this happen? I get the handlers are processed server side, but I do not know how to go around this issue.
var getManager = function (functionName, contentDiv) {
console.log("aircraft manager refresh called");
$.ajax({
type: "GET",
url: '#Url.Action(functionName, "AdminTools")',
cache: false,
data: {},
error: function () {
alert("An error occurred.");
},
success: function (data) {
$("#".concat(contentDiv)).html(data);
}
});
}
I highly recommend you don't couple your server-side and client-side code like:
$.ajax({
type: "GET",
url: '#Url.Action(functionName, "AdminTools")', //THIS
It will turn into a maintenance nightmare. Instead:
<div id="#contentDiv" data-url="#Url.Action(functionName, "AdminTools")">
#* content *#
</div>
then
var getManager = function (functionName, contentDiv) {
console.log("aircraft manager refresh called");
var url = contentDiv.data("url");
$.ajax({
type: "GET",
url: url,
// .....
if you decide later to have multiple contentdivs each can have it's own url, and your code is reusable.
I created self-signed certificate and bind with site for using https protocol and also its working fine in IIS but problem is that whenever I access contained webservice url(https://webservice/webmethod) into jquery ajax call for posting data and its cant work.
enter code here
<script src="jquery-1.9.1.js"></script>
<script type="text/javascript">
function btncallWebService() {
$.ajax({
//url is just for understanding
url: 'https://localhost/.../EditFormServices.asmx/WebSvcSave',
data: { sData:"bbbb" },
method: 'post',
dataType: 'xml',
success: function (respo) {
alert("success"+respo.d);
},
error: function (error) {
alert("error");
}
});
}
</script>
Here we go:
Your url is wrong
<script type="text/javascript">
function btncallWebService() {
$.ajax({
//url is just for understanding
url: '/WebSvcSave',
data: { sData:"bbbb" },
type: 'POST',
dataType: 'xml',
success: function (respo) {
alert("success"+respo.d);
},
error: function (error) {
alert("error");
}
});
}
</script>
Hope it helps;)
The way I'm trying to perform this action is like this:
var postPlaylistAjax = $.ajax({
type: 'delete',
url: 'http://api.deezer.com/user/me/playlists?request_method=delete&
access_token='+
encodeURIComponent(deezerAccessToken)+'&playlist_id=' +
encodeURIComponent(playlistId) + '&output=jsonp',
dataType: 'jsonp',
success: function() {
alert('Deleted');
},
error: ajaxError,
});
(When I try it in web the result is true but it doesn't delete the playlist).
Since the API description for deleting a playlist is the following
request_method = delete
https://api.deezer.com/playlist/{playlist_id}
I'm getting trouble to execute it in javascript
solved it:
function deleteDeezerPlaylist(playlistId) {
var postPlaylistAjax = $.ajax({
type: 'post',
url: 'http://api.deezer.com/playlist/'+encodeURIComponent(playlistId)+'?request_method=DELETE&access_token='+encodeURIComponent(deezerAccessToken)+'&output=jsonp',
dataType: 'jsonp',
error: ajaxError,
});
return postPlaylistAjax.then(function (response) {
return response.id;
});
}
I'm calling php file through ajax call and if it returns nothing i want to redirect user to another page (It's for error reports, if it doesn't return anything it means that user logged in). Tried to add error section but it doesn't work. Any suggestions will help. Thanks! Btw, I have small jQuery function at the top of the ajax function, why it breaks my whole ajax call?
ajax.js
function loginAjax() {
//$("#email_errors").empty(); //This function doesnt work and kills whole ajax call. Here is loginAjax function call line - <button type = "submit" id = "push_button" onclick = "loginAjax(); return false">PushMe</button>
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
success: function(data) {
$("#login_error").html(data.login_message);
}
});
}
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
success: function(data) {
$("#login_error").html(data.login_message);
},
error: function(){
window.location.replace("http://stackoverflow.com");
}
});
}
To redirect using javascript all you need to do is override the location.href attribute.
function loginAjax() {
$.ajax({
url: "Classes/call_methods_login.php",
type: "POST",
dataType: "json",
data: {
login_email: $("#login_email").val(),
login_password: $("#login_password").val(),
},
// the success method is deprecated in favor of done.
done: function(data) {
$("#login_error").html(data.login_message);
},
fail: function(data) {
location.href="path/to/error/page";
}
});
}
I have an ajax function is called when a form is completed. It is suppose to redirect to a certain page if there is a success for a failure. When I run the form in IE, it works perfectly but in Firefox, the page does not redirect at all. It just refreshes the page. Here is the ajax code:
$.ajax({
url: "someURL",
type: "POST",
dataType: "xml",
data: params,
success: function () { window.location = 'success_page.htm' },
failure: function () { window.location = 'error_page.htm' }
});
Well, there's a minor mistake in your code: you are missing some semicolons:
$.ajax({
url: "someURL",
type: "POST",
dataType: "xml",
data: params,
success: function () { window.location = 'success_page.htm'; },
failure: function () { window.location = 'error_page.htm'; }
});
If this still doesn't resolve your problem, then I would guess there is something wrong with your params variable. Could you show us the whole code?
try
window.location = '/error_page.htm'
Sometimes working with IE I had the same problem, I use window.location.href instead of window.location