XMLHttpRequest Exception 101 on IOS devices - c#

I recently started getting the following message on a jquery ajax call only on IOS devices:
ERROR: NETWORK_ERR:
XMLHttpRequest Exception 101
The ajax call worked well for months on all devices but one of my clients started getting this message last week.
I have read some about it being a cross domain request problem but that should not be applicable in this case.
I have also read that changing async to true will fix the problem but I want to avoid that if I can.
Here is the ajax call:
the serverSideFunction parameter is in the form "AdvancedDistribution.aspx/SaveClicked"
where AdvancedDistribution.aspx is of course the aspx file and SaveClicked is the static WebMethod(C#).
para is just a 2d array with the parameter values.
function ajaxCall(serverSideFunction, para)
{
ajaxReturn = "";
var dataPara = "{";
for (var i = 0; i < para.length; i++)
{
dataPara += "'" + para[i][0] + "':'" + para[i][1] + "'";
if (i < para.length - 1)
dataPara += ",";
}
dataPara += "}";
$.ajax({
type: "POST",
url: serverSideFunction,
data: dataPara,
async: false,
//&&JS01112013.2 Fix bug caused by IOS6 ajax caching
headers: {"cache-control": "no-cache"},
beforeSend: function (xhr)
{
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg, status)
{
ajaxReturn = msg.d;
},
error: function (xhr, msg, e)
{
alert(e); //Error Callback
alert('Ajax Callback Failed');
}
});
return ajaxReturn;
}
Since this is still working on most devices I'm hoping that it will be as simple as just adding and IOS required header to the ajax call.
Any Ideas?
Thanks.

Related

Ajax Webmethod not being called

I make a total of four Ajax calls in my .NET application. Three of them work without a hitch except the last one.
Note: I HAVE to use .aspx for these calls and not mypage.aspx/mymethod because of our architectural constraints.
Ajax call that works:
$.ajax({
type: "POST",
url: "myaddress/GenerateOpinionHTML.aspx",
data: JSON.stringify({ id: featureId, pageNumber: pageNumberIndex }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
SOME PROCESSING (IT WORKS)
},
error: function (xhr, status, error) {
var err = xhr.responseText;
console.log(err);
}
});
and
[WebMethod]
public static string GenerateOpinionHTML(int id, int pageNumber)
{
// ...
}
Ajax call that does not work:
console.log("SUBMITOPINIONCLICK");
var param = " ";
$.ajax({
type: "POST",
url: "myaddress/SaveOpinion.aspx",
data: JSON.stringify({ parameter: param}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
console.log("SAVE OPINION SUCCESSFUL");
console.log(msg.d);
CloseLB('GiveOpinionLB');
},
error: function (xhr, status, error) {
var err = xhr.responseText;
console.log("ERROR " + "STATUS: " + status);
}
});
and
[WebMethod]
public static string SaveOpinion(string parameter)
{
// ...
}
The web method SaveOpinion is never called according to the logs. Do you have any ideas or suggestions? I tried adding parameters, without parameters, checking my web.config file (though I shouldn't have since the other calls work)...
The error I get on the browser console is a "parseerror". I'm certain I wouldn't be getting an error if the method was called.
I think your URL should be like
url: "Your FolderName/PageName/Function Name",
Like
url: "myaddress/SaveOpinion.aspx/SaveOpinion"
but in your code this is different so that please check.
Have you checked if method SaveOption return something to the client?
If you specify dataType as json, you should return (at least): {}
Ok so we "solved" it. We just found a very dirty band-aid workaround that works.
We made a custom handler (.ashx) that we defined in our architecture as a SaveOpinion.aspx page.
We then called this custom handler page with jQuery and voilĂ  it works, we had to obviously pass all necessary parameters manually, ie. fetching all values from textBoxes etc with jQuery and not from the context as we did before.
Since this is run in some sort of thread (I don't really know the details) we had to configure it so that it simulates the same user authentification.
Anyway I hope this provides some measure of guidance for those with this kind of obscure problems.

WCF Rest with PUT method on calling from client side changes to GET method in header request and fails to perform operation

I have a Restfull WCF service running.
All the operation works perfect and tested.
But when I try to call one of the PUT operation from client side using jquery JSON the header request changes to GET() method though I have mentioned PUT as method.
Tested on fiddler same 405 method not allowed error.
I know as it is a PUT method we can not apply GET but on client side if I use PUT() it automatically changes to GET in header request and fails.
Why it is happening can't get to fix it.Any help or ideas?
My client code for service request is as follows:
function UpdateRating(radioValue) {
jQuery.support.cors = true;
var star = (Math.floor(radioValue * 2) / 10).toFixed(2);
$.ajax({
type: "PUT",
url: ServiceURL + "xxx.svc/xml/updatescoreforvideo?vid=" + videoId + "&uid=" + userId + "&score=" + star,
data: "{}",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "jsonp",
success: function (data, status, jqXHR) {
alert("you rated : "+ star + "star");//show alert on success //test
},
error: function () {
alert('Service call error occured');
}
});
}
My fiddler /firebug error reports :

Redirect after an ajax request in a click event

I'm using JScript + ASP.NET. I got a form with 2 inputs (user and password) and a button. What I'm trying to do is to:
1- Fire a click event
2- Look inside a database if the user exist
3- Give back the answer
4- If the answer is true, POST some data to an other page AND redirect to it.
I first tried to do this with ASP.NET. To POST data with ASP.NET I need to use PostBackUrl property, but the problem is that PostBackUrl ignore my click event.
I then tried to do this with jscript. On my click event (jquery), I use $.ajax to POST data to access my database, give the answer back in json...and I'm stuck there. In both method, I'm stuck at point 4.
ASP.NET
protected void SignIn_OnClick(object sender, EventArgs e)
{
Clients client = (Clients)clientDAO.getUsername(text1.Text, password2.Text);
if (client != null)
{
Session.Add("SessionNoClient", "1272");
Session.Add("CurrentQuote", "-1");
Session.Add("UnitSystem", "0");
Session.Add("SessionAdministrator", "0");
//How to redirect with POST here
}
}
JScript:
$("#m_bLogin").click(function () {
var username = $("#text1").val();
var password = $("#password2").val();
var form = $("#formClient");
$.ajax({
url: '../../Class/LoginAjax.asmx/GetLoginInformation',
data: "{ 'Name':'" + username + "','Password':'" + $("#password2").val() + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
//My Json returns {"'Name':'Bob','Password':'1234'} and I'm not able to access Name or Password property. I tried data.d, data.d.Name, eval(data.d.Name) etc...
form.submit();
},
error: function (XMLHttpRequest, textStatus, error) {
alert(error);
}
});
});
You could do something like that:
$.ajax({
url: '../../Class/LoginAjax.asmx/GetLoginInformation',
data: "{ 'Name':'" + username + "','Password':'" + $("#password2").val() + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
//My Json returns {"'Name':'Bob','Password':'1234'} and I'm not able to access Name or Password property. I tried data.d, data.d.Name, eval(data.d.Name) etc...
form.submit();
},
error: function (XMLHttpRequest, textStatus, error) {
alert(error);
}
}).done(function() {
window.location.href = "YourNewPage.aspx";
});

C# webservice calls using jQuery 1.7.1 /eval/seq/

So here's the problem. I have three pages that make web service calls. The first time I land on the page and make the call it works fine, however if I switch to the second page it tries to make a web service call to the wrong service. Here's some info:
pages:
Page1.aspx - has Page1.js
Page2.aspx - has Page2.js
js files:
Page1.js
var filterCriteria = "";
function GetList() {
$.ajax({
type: "POST",
url: "/webServices/Page1.asmx/Page1List",
contentType: "application/json; charset=utf-8",
data: "{'letter':'" + filterCriteria + "'}",
dataType: "json",
success: function (result) {
DisplayList(result.d);
}
});
}
function GetSearchResults() {
$.ajax({
type: "POST",
url: "/webServices/Page1.asmx/Page1FilteredList",
contentType: "application/json; charset=utf-8",
data: "{'searchCriteria':'" + $("#Search").val() + "'}",
dataType: "json",
success: function (result) {
DisplayList(result.d);
}
});
}
function DisplayList(object) {
var html = '';
for (var i = 0; i < object.length; i++) {
//format results and append
}
if (object.length == 0) {
html += "<li class=\"filteredList\" style=\"padding: 10px;\">No Results Found</li>";
}
$("#Page1List").html(html);
}
Page2.js
var filterCriteria = "";
function GetList() {
$.ajax({
type: "POST",
url: "/webServices/Page2.asmx/Page2List",
contentType: "application/json; charset=utf-8",
data: "{'letter':'" + filterCriteria + "'}",
dataType: "json",
success: function (result) {
DisplayList(result.d);
}
});
}
function GetSearchResults() {
$.ajax({
type: "POST",
url: "/webServices/Page2.asmx/Page2FilteredList",
contentType: "application/json; charset=utf-8",
data: "{'searchCriteria':'" + $("#Search").val() + "'}",
dataType: "json",
success: function (result) {
DisplayList(result.d);
}
});
}
function DisplayList(object) {
var html = '';
for (var i = 0; i < object.length; i++) {
//format results and append
}
if (object.length == 0) {
html += "<li class=\"filteredList\" style=\"padding: 10px;\">No Results Found</li>";
}
$("#Page2List").html(html);
}
So both have the same calls and the same information and the only real difference is that the results are different and they make a web service call to different web services that get different data.
Now each time that I switch between I get a new js file which is
jQuery-1.7.1.min.js/eval/seq/1
jQuery-1.7.1.min.js/eval/seq/2
jQuery-1.7.1.min.js/eval/seq/3
jQuery-1.7.1.min.js/eval/seq/4
depending on how many times I switch back an forth. Is there any way to stop the eval or is there something in my code that is causing the jQuery to store evals of the code I am using and what can I do to resolve it?
So the problem was that I was loading page transitions from jquery mobile. What was happening was that jquery mobile appends new page data to the DOM instead of forcing a page load. This was causing both javascript files to be loaded simultaneously meaning that which ever js file was loaded last was the primary and because both js files were calling functions with the same name it would load them multiple times.
Resolution
remove the $.mobile.load() event and force the click event to append the pathname to the url
$("#GoPage1").on("click", function () { window.location = "/dir/Page1.aspx"; });
$("#GoPage2").on("click", function () { window.location = "/dir/Page2.aspx"; });

getting"SyntaxError: JSON.parse: unexpected character" error while make ajax call from user control page in asp.net

i use first time ajax call from asax page.
it is working fine i am getting data in C# page and but when trying get success function than i am getting error msg in error function
"SyntaxError: JSON.parse: unexpected character"
here is my code
var options = {
type: "POST",
url: "ChemistrieAddToCart.aspx",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function () {
alert("sucsess");
},
error: function (xhr, status, error) {
alert("failed" + xhr.responseText);
alert(error);
alert(status);
}
};
var returntext = $.ajax(options).responseText;
if (returntext = "added") {
alert("Matched");
window.location="shoppingcart.aspx"
}
else {
alert("not completed");
}
Thanks.
if you are passing <img src="1-800-optisource.com/Email/image/jsonstring.jpg"; width="497" height="394"/> as Json string that its is wrong you might look at json format first than pass the value might give you idea and resolve your issue
check json over here : http://www.json.org/

Categories

Resources