With this post I would like to ask a question regarding a problem i'm running into.
I have a webpage using jQuery UI elements. Some data is collected and send to a webservice using JSON.
The data I'm sending is very large (20000 chars) but is received perfect in the webserice. Using JSON.NET I'm able to read the data back into a list of objects. So far, everything is running smooth.
But when processing the data in the Webcervice to update multiple tables, some very strange behaviour occures. The webmethode doesn't process the code from top to bottom. It jumps back an forth. I've added some debug lines between each step and the result
was this:
--> Step 1
--> Step 3 - All done
--> Step 2
--> Step 3 - All done
--> Step 3 - All done
This doesn't make sence... But the result is that my database get's damaged !!! The result is always different when I submit the data.
In many cases, the frontend function defined in $.Ajax function to process when the operation is completed is triggerd multiple times... (Showing a messagebox confirming that the data is saved)
How do I solve this issue? This is very strange... How to I force the webservice to run smooth from top to bottom and running the code line by line.... I've never seen this before...
Thanx
Ps
Some code from the front end
function Save() {
var strIssueID = $("#hdfIssue").attr("value");
var ArticleListJSON = JSON.stringify(myIssueArticleList);
var PageListJSON = JSON.stringify(myIssuePageList);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/SaveData",
dataType: "json",
data: "{IssueID:'"+ strIssueID + "', PageData:'" + PageListJSON + "', ArticleData: '" + ArticleListJSON + "' }",
success: insertCallback,
error: errorCallback
});
}
function insertCallback(result) {
alert("Data saved !");
}
function errorCallback(XMLHttpRequest, textStatus, errorThrown) {
alert("Error writing to the database ! Shit happens...");
}
You should debug your code and why and who is triggering it multiple times.
In your javascript ajax call put console.log('executed!'); just make sure that you in chrome browser press F12 got to console and check if it running one or multiple times.
Do the same on your server side, with relevant tools of course!
Marked as answer by tmelis on Jan 26, 2013 04:38 PM
tmelis
Member
3 Points
10 Posts
Webservice doesnt process top to bottom
Jan 24, 2013 01:39 PM|LINK
Hi,
With this post I would like to ask a question regarding a problem i'm running into.
I have a webpage using jQuery UI elements. Some data is collected and send to a webservice using JSON.
The data I'm sending is very large (20000 chars) but is received perfect in the webserice. Using JSON.NET I'm able to read the data back into a list of objects. So far, everything is running smooth.
But when processing the data in the Webcervice to update multiple tables, some very strange behaviour occures. The webmethode doesn't process the code from top to bottom. It jumps back an forth. I've added some debug lines between each step and the result was this:
--> Step 1
--> Step 3 - All done
--> Step 2
--> Step 3 - All done
--> Step 3 - All done
This doesn't make sence... But the result is that my database get's damaged !!! The result is always different when I submit the data.
In many cases, the frontend function defined in $.Ajax function to process when the operation is completed is triggerd multiple times... (Showing a messagebox confirming that the data is saved)
How do I solve this issue? This is very strange... How to I force the webservice to run smooth from top to bottom and running the code line by line.... I've never seen this before...
Thanx
Ps
Some code from the front end
function Save() { var strIssueID = $("#hdfIssue").attr("value"); var ArticleListJSON = JSON.stringify(myIssueArticleList); var PageListJSON = JSON.stringify(myIssuePageList); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService.asmx/SaveData", dataType: "json", data: "{IssueID:'"+ strIssueID + "', PageData:'" + PageListJSON + "', ArticleData: '" + ArticleListJSON + "' }", success: insertCallback, error: errorCallback }); } function insertCallback(result) { alert("Data saved !"); } function errorCallback(XMLHttpRequest, textStatus, errorThrown) { alert("Error writing to the database ! Shit happens..."); }iluxa.v
Member
215 Points
47 Posts
Re: Webservice doesnt process top to bottom
Jan 24, 2013 01:46 PM|LINK
Just
$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService.asmx/SaveData", dataType: "json", async:false, data: "{IssueID:'"+ strIssueID + "', PageData:'" + PageListJSON + "', ArticleData: '" + ArticleListJSON + "' }", success: insertCallback, error: errorCallback });add async:false to prevent the asynchronius request
tmelis
Member
3 Points
10 Posts
Re: Webservice doesnt process top to bottom
Jan 24, 2013 02:11 PM|LINK
Hi,
Thanx for your feedback. The new result is...
--> Start
--> Step 1
--> Step 2
--> Step 3 - All done
--> Start
--> Step 1
--> Step 2
--> Step 3 - All done
--> Start
--> Step 1
--> Step 2
--> Step 3 - All done
--> Start
--> Step 1
--> Step 2
--> Step 3 - All done
--> Start
--> Step 1
--> Step 2
--> Step 3 - All done
The webservice seems to process from top to bottom, but is still triggered multiple times in stead of only a single time.
How do I solve this issue?
iluxa.v
Member
215 Points
47 Posts
Re: Webservice doesnt process top to bottom
Jan 24, 2013 02:14 PM|LINK
You should debug your code and why and who is triggering it multiple times.
In your javascript ajax call put console.log('executed!'); just make sure that you in chrome browser press F12 got to console and check if it running one or multiple times.
Do the same on your server side, with relevant tools of course!
tmelis
Member
3 Points
10 Posts
Re: Webservice doesnt process top to bottom
Jan 26, 2013 04:38 PM|LINK
Hi,
Thanx for your feedback. I found out by debugging that jQuery fired the event multiple times, even when the button was only pressed once.
When I moved the click function outside the "$(document).ready" function, the problem was solved and the event was only triggerd once.
Thanx again for your insight.