im trying to send data from sidenav located in my default.aspx page to another page called addstudy.aspx . im getting the alert that the study was inserted in the database , but in fact nothing is inserted , instead , in my console im getting , 500 internal
server error , any help please? my code is below
Default.aspx ( on button click)
<script type="text/javascript">
function insert() {
var xmlhttp = new XMLHttpRequest();
var anchors = document.getElementById('mySidenav').getElementsByTagName('a');
for (var i = 0; i < anchors.length; i++) {
alert(anchors[i].text);
alert(anchors[i].href);
xmlhttp.open("GET", "addnewstudy.aspx?nm=" + anchors[i].text + "&gd=" + anchors[i].href + "&opr=insert", false);
xmlhttp.send(null);
alert("New Study inserted in database");
}
}
</script>
Consider changing the design a bit to use a Web Method rather than a calling the page and running through the page life cycle. Rather than sending a bunch of requests, I would send an array of objects.
Your code seem ok, and I do a test on my side with your code, which works for me. To troubleshoot the issue, you can try to specify testing values for querystrings and set breakpoint inside
Page_Load event of addnewstudy.aspx, and then you can debug your code to check if it works as expected.
var xmlhttp = new XMLHttpRequest();
var nm = "testnm";
var gd = "testgd";
xmlhttp.open("GET", "addnewstudy.aspx?nm=" + nm + "&gd=" + gd + "&opr=insert", false);
xmlhttp.send(null);
With Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
17 Points
70 Posts
ajax nothing written to the database
Dec 07, 2017 07:01 AM|NAF|LINK
im trying to send data from sidenav located in my default.aspx page to another page called addstudy.aspx . im getting the alert that the study was inserted in the database , but in fact nothing is inserted , instead , in my console im getting , 500 internal server error , any help please? my code is below
Default.aspx ( on button click)
All-Star
52803 Points
15764 Posts
Re: ajax nothing written to the database
Dec 07, 2017 07:31 AM|oned_gk|LINK
How about if you open the url dierctly in address bar?
or you can evaluate what the anchor text and href value, may content some unwanted characters
Suwandi - Non Graduate Programmer
Member
17 Points
70 Posts
Re: ajax nothing written to the database
Dec 07, 2017 07:43 AM|NAF|LINK
if i open the url directly in the browser , and fill in the nm and the gender , values that i fill are written in the database....
i am stuck i cant figure out what is happening...
All-Star
53641 Points
23992 Posts
Re: ajax nothing written to the database
Dec 07, 2017 02:22 PM|mgebhard|LINK
The posted code looks ok. There is probably an issue elsewhere in the code base.
Keep in mind that synchronous AJAX request has been deprecated in some browsers which might have something to do with the issue.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
Plus the code is not handling the response.
Consider changing the design a bit to use a Web Method rather than a calling the page and running through the page life cycle. Rather than sending a bunch of requests, I would send an array of objects.
All-Star
40565 Points
6233 Posts
Microsoft
Re: ajax nothing written to the database
Dec 21, 2017 05:41 AM|Fei Han - MSFT|LINK
Hi NAF,
Your code seem ok, and I do a test on my side with your code, which works for me. To troubleshoot the issue, you can try to specify testing values for querystrings and set breakpoint inside Page_Load event of addnewstudy.aspx, and then you can debug your code to check if it works as expected.
With Regards,
Fei Han