OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

AJAX bring the complete file instead data - VB.NET

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

Guest
hope you can help me with this issue. I'm trying to get a list from the server side to javascript, using AJAX and VB.NET. I tried several things but it always return the complete file instead the list.

I tried with Javascript and Jquery AJAX, but always had the same result. In resume: Connection on DAL.vb file -> Calling the DAL on Presenter.vb -> Returns to ASCX.VB file code behind.

Code:
**My Presenter:**
      Public Function GetMenuFromDB() As String
            ....authorization code
                    valueToSet = _accDAL.GetMenuDetailsByUser(UserID) -> my connection to DB
                End If
                If valueToSet.Count > 0 Then
                    Dim serializer As New JsonSerializerOptions()
                    Dim json As String = Text.Json.JsonSerializer.Serialize(valueToSet)
                    Return json
                End If
      End Function

**My file ascx.vb:**
<WebMethod()>
        Protected Shared Function GetMenuFromDB(sender As Object, e As EventArgs) As String
            Dim presenter As New MenuPresenter()
            Return presenter.GetMenuFromDB() 
        End Function]

**My JS:**
function getMenuByUser() {
    var xhr = new XMLHttpRequest();
    var url = "~/Menu.ascx/GetMenuFromDB"
    xhr.open("GET", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(xhr.responseText);
        }
    };
    xhr.send();
}

OR Jquery:
$(document).ready(function () {
    $.ajax({
        type: "GET",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: "~/Menu.ascx/GetMenuFromDB",
        success: function (result) {
            debugger;
            console.log(result);
        },
        error: function (xhr, textStatus, error) {
            console.log(error);
        }
    });
});

But I put a breakpoint on the ascx.vb and never enters. I change the URL for differents types but doesn't works. Also I try to move the method to point the aspx file instead ascx, just in case, but it worked with the same result.

Thanks.

<p>hope you can help me with this issue. I'm trying to get a list from the server side to javascript, using AJAX and VB.NET. I tried several things but it always <em><strong>return the complete file instead the list.</strong></em></p>
<p>I tried with Javascript and Jquery AJAX, but always had the same result.
In resume:
Connection on DAL.vb file -> Calling the DAL on Presenter.vb -> Returns to ASCX.VB file code behind.</p>
<pre><code>**My Presenter:**
Public Function GetMenuFromDB() As String
....authorization code
valueToSet = _accDAL.GetMenuDetailsByUser(UserID) -> my connection to DB
End If
If valueToSet.Count > 0 Then
Dim serializer As New JsonSerializerOptions()
Dim json As String = Text.Json.JsonSerializer.Serialize(valueToSet)
Return json
End If
End Function

**My file ascx.vb:**
<WebMethod()>
Protected Shared Function GetMenuFromDB(sender As Object, e As EventArgs) As String
Dim presenter As New MenuPresenter()
Return presenter.GetMenuFromDB()
End Function]

**My JS:**
function getMenuByUser() {
var xhr = new XMLHttpRequest();
var url = "~/Menu.ascx/GetMenuFromDB"
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send();
}

OR Jquery:
$(document).ready(function () {
$.ajax({
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "~/Menu.ascx/GetMenuFromDB",
success: function (result) {
debugger;
console.log(result);
},
error: function (xhr, textStatus, error) {
console.log(error);
}
});
});
</code></pre>
<p>But I put a breakpoint on the ascx.vb and never enters.
I change the URL for differents types but doesn't works.
Also I try to move the method to point the aspx file instead ascx, just in case, but it worked with the same result.</p>
<p>Thanks.</p>
 

Latest posts

Top