Opera, Wii, Ajax, Jquery and asp.net - asp.net

I've written an ajax-enabled web page intended for use on my Wii. However, ajax doesn't appear to work on the Wii's Opera browser. This page works in IE, Chrome and FF, but not in Safari or Opera.
Here is my jQuery test ajax call:
$.ajax({
type: "POST",
url: "DefaultWebService.asmx/Hello",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) { alert(msg.d); },
error: function() { alert("error in DefaultWebService.asmx/Hello"); }
});
Here is my test web service method:
[WebMethod]
public string Hello()
{
return "hello there";
}
There are no calls to DefaultWebService.asmx in my web server logs, so the browser isn't even trying to make the ajax request.
Are there any work-arounds available to get this working on the Wii?
Thanks!

after a month I hope you've found the solution, but if you haven't I'd like to help out. I wrote a pretty basic test, just this:
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
echo file_get_contents('php://input');
exit;
}
?>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
url: location.href,
data: '{"test":"passed" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) { alert(msg.test); },
error: function() { alert("error while testing"); }
});
</script>
but it does work just fine in the Opera versions I tried it in (including some early 9.x versions that might be aligned to the Wii one - I'm not sure what the closest desktop equivalent is though)

Have you tried changing the data being posted? This looks similar (though obviously not identical) to the issue posted here: jQuery syntax error on POST in Opera

Not too familiar with ASP.. could it be that you need to JSON encode the return value? Or does "[WebMethod]" take care of that? Try this:
return "\"hello there\"";

Related

web method using jqueryajax in asp.net not working in Mozilla firefox

I am working on asp.net website in which i am getting data by using jquery ajax.
here is my code.
function PostSubChapter(qbt_id) {
debugger;
var v1 = 'qbt_id:' + qbt_id;
$.ajax(
{
type: "POST",
url: '<%= ResolveUrl("~/QuestionBankSubChapters.aspx/GetChapters") %>',
data: '{' + v1 + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
if (result.status === "OK") {
alert('Comment posted');
}
else {
fnDisplaySubChapter(result, qbt_id);
}
},
error: function (req, status, error) {
alert("Sorry! Post failed due to error");
}
});
}
and my web method is
[WebMethod]
public static List<BO.QuestionBankSubChapters> GetChapters(int qbt_id)
{
BAL.QuestionBankSubChapters oQBTSC = new BAL.QuestionBankSubChapters();
List<BO.QuestionBankSubChapters> lstQBTSC = oQBTSC.getQuestionBankSubChapters(qbt_id);
return lstQBTSC;
}
These is working very fine in chrome an IE but not showing any result in case of FireFox
call is going properly to web method but at the time of getting result from it is calling Error function.It has to call another function present in sucess function but not calling that function.
Pls help me these.
for your understanding here i am mentioning the link of the website
Link is : "http://skillgun.com/Home.aspx"
Open these in Fire fox and chrome both then Click on Arithmetic then it will display 2nd screen.
Just see the o/p in both the browser you'll understand. In chrome its working properly but in Firefox its not.I am not getting understand what is the reason behind these.Sample code already i mentioned above.
I am using jquery-1.8.3.min.js for getting the result.The callback function is working fine in chrome and IE but not working in FF
Please help me....
Your page method returns correct response, problem is with your other code that you've not posted but I could see in FF console.
You've used innerText at many places and FF doesn't support it. Try innerHTML instead.
For waitprocess div you're not using # along with it's id while using Jquery Selector $ and hence it is visible all the time.

After Server.Transer Ajax doesn't work when requesting a page method

In the page_load of page A I Server.Transfer to Page B (Server.Transfer("B.aspx");)
Then on page B I have a simple html button that has the onclick="ajaxFunction();";
function ajaxFuntion()
{
$.ajax({
type: "POST",
url: "B.aspx/MyPageMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: false
});
}
I get ajax error "Method not Found"
When I use Repsonse.Redirect instead of Server.Transfer, it works.
But I need to use Server.transfer. Is there a fix here?
Thx
I think it's because B.aspx renders in the context of A.aspx, and so it's not B.aspx you are currently in, it's A.aspx, as far as the browser is concerned. You can try A.aspx/MyPageMethod and see if it will work...

Why do I need to use .d to access data returned by jQuery AJAX?

I've put together some jQuery AJAX code using some tutorials I found on the internet. I'm new to jQuery and want to learn how to do things betters. I have a coworker who put together a beautiful web application using a lot of jQuery.
The thing I'm most confused about here is: why is it necessary to use the ".d" when referring to the response of my web method and what does it stand for?
// ASP.net C# code
[System.Web.Services.WebMethod]
public static string hello()
{
return ("howdy");
}
// Javascript code
function testMethod() {
$.ajax({
type: "POST",
url: "ViewNamesAndNumbers.aspx/hello",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg); // This doesn't display the response.
alert(msg.d); // This displays the response.
} // end success:
}) // end $.ajax
It was added in ASP.NET 3.5’s version of ASP.NET AJAX to prevent you from being vulnerable to this exploit: http://haacked.com/archive/2009/06/25/json-hijacking.aspx
(Answer sourced from http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/)
Microsoft does this to protect you from a security exploit. See the bottom of This Page for more information.
I guess alert(msg) displays "[object Object]" ?
If so it's because the object which is parsed through window.JSON (which happens under the hood when specifying json as dataType) does really look:
object = {
d: "some data"
}
Check what you are generating in ViewNamesAndNumbers.aspx/hello

I want to display a circular progress indicator using jquery in asp.net when textbox textchange event occurs

I want to display a circular progress indicator using jquery in asp.net when textbox textchange event occurs. When user enters some value in a textbox and textchange event occurs or when user loses the focus on that textbox, system checks values in databases. I want to give user a progress indicator type when query is in progress.
How can I accomplish this with jquery?
Code here:
$("#Txturl").blur(function() {
$.ajax({
type: "POST",
url: "Default.aspx/Getvalue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
///to to do here? i ve no idea;
}
});
return false;
});
This is relatively straightforward. You would start by creating the animated GIF for your indicator (or download a freely available one) and add it to your site. Then in your Javascript, you would add something closely resembling the following:
$('#yourTextBox').change(
function(){
$("#yourProgressImg").show();
$.ajax({
type : "get",
url : <your request uri>,
success: <what to do if it comes back happy>
fail: <what to do if it fails>
complete: function(){ $("#yourProgressImg").hide(); }
});
}
);
The complete functionality of the $.ajax() function is here: http://api.jquery.com/jQuery.ajax/
Not sure how every other site does it, but I would show an animated GIF on the textchange event and hide it in the AJAX success (or failure) function.
Have a hidden div with your animated GIF.
<style>.hidden { display: none; }</style>
<div class="hidden"><img src="spinner.gif" /></div>
Then show it on change and hide it in the success or error callback.
$('#mytextbox').change(function(){
$('#divwithGIF').show();
$.ajax({
type: 'POST',
url: 'Default.aspx/Getvalue',
data: '{}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: true,
complete: function(msg){
$('#divwithGIF').hide();
};
});
});
Repeat for the blur() event.
See my answer on this one: jquery submit and loading gif for an example of how you can construct a global (on the page) event monitor for ajax to display an animated gif as you describe. You can customize this as you wish for your events.

How to refresh particular part of my web page?

I want to refresh only a single part of my page not the whole.
How ?
I wouldn't recommend Update Panel but you can use jQuery $.load() method which is pretty slick. Once you start using it, it helps you a lot.
So use Ajax... long story short.
Edit :
Maybe this article help as well :
Why Update Panels are Dangerous :
http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/
In web forms you can use the update panel
See here for example
You can also use JQuery although it depends on what you are trying to do and to what complexity.
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "YourPage.aspx/apply",
dataType: "json",
data: json.stringify(""),
success: function (result) {
alert(result);
// window.location.href = "ClubCreation.aspx";
},
Error: function () {
alert('error');
}
});
[HttpPost]
public string apply()
{
return "Hi";
}
You can use Ajax to solve your problem this code will help you

Resources