Answered by:
Error with jquery ajax json function

Question
-
User368742804 posted
Here's the pertinent section of the .aspx page
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ProductInfoCRUD.aspx.vb" Inherits="WebApplication1.ProductInfoCRUD" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>jQuery Gridview Crud Operations Example</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> <script type="text/javascript"> var prodid = 0, opstatus = ''; $(function () { BindGridview(); }); function BindGridview() { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "jQueryGridviewCrudOperations.aspx/BindGridview", data: "{}", dataType: "json", success: function (data) { var result = data.d; for (var i = 0; i < result.length; i++) { $("#gvDetails").append('<tr><td>' + result[i].productid + '</td><td>' + result[i].productname + '</td><td>' + result[i].price + '</td><td><img src=edit.jpg width=20px height=20px onclick=updatedata(' + result[i].productid + ', "' + result[i].productname + '","' + result[i].price + '") > <img src=delete.png onclick=deleterecords(' + result[i].productid + ')> </td></tr>'); } }, error: function (data) { var r = data.responseText; var errorMessage = r.Message; alert(errorMessage); } }); }
Here's the pertinent section of the aspx.vb page:
Imports System.Collections.Generic Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.Services Imports System.Data Imports System.Data.SqlClient Partial Class ProductInfoCRUD Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then BindColumnToGridview() End If End Sub Private Sub BindColumnToGridview() Dim dt As New DataTable() dt.Columns.Add("ProductId") dt.Columns.Add("ProductName") dt.Columns.Add("Price") dt.Columns.Add("Edit") dt.Rows.Add() gvDetails.DataSource = dt gvDetails.DataBind() gvDetails.Rows(0).Visible = False End Sub <WebMethod()> _ Public Shared Function BindGridview() As ProductDetails() Dim dt As New DataTable() Dim details As New List(Of ProductDetails)() Using con As New SqlConnection("Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WingtipToys;Integrated Security=True") con.Open() Dim cmd As New SqlCommand("crudoperations", con) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@status", "SELECT") Dim da As New SqlDataAdapter(cmd) da.Fill(dt) con.Close() For Each dtrow As DataRow In dt.Rows Dim product As New ProductDetails() product.productid = dtrow("productid").ToString() product.productname = dtrow("productname").ToString() product.price = dtrow("price").ToString() details.Add(product) Next End Using Return details.ToArray() End Function
popup says
The page at localhost:49684 says:
undefined
Chrome browser Developer Tools Console shows:
POST http://localhost:49684/jQueryGridviewCrudOperations.aspx/BindGridview 404 (Not Found)
POST http://localhost:49684/jQueryGridviewCrudOperations.aspx/BindGridview 404 (Not Found)
Thursday, November 12, 2015 12:02 PM
Answers
-
User475983607 posted
It looks like the page with the web method is ProductInfoCRUD.aspx but the AJAX request is pointing to jQueryGridviewCrudOperations.aspx.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 12, 2015 1:53 PM
All replies
-
User475983607 posted
It looks like the page with the web method is ProductInfoCRUD.aspx but the AJAX request is pointing to jQueryGridviewCrudOperations.aspx.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 12, 2015 1:53 PM -
User61956409 posted
Hi mmmtbig,
Please make sure whether the request url is correct. As mgebhard said, your web page is “ProductInfoCRUD.aspx”, but you specify the AJAX url option to
url: "jQueryGridviewCrudOperations.aspx/BindGridview",Besides, this article explained how to make a call to ASP.Net WebMethod using jQuery AJAX, please refer to it.
http://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx
Best Regards,
Fei Han
Friday, November 13, 2015 12:44 AM -
User632428103 posted
Hello,
it's seems the page name isn't the same :
On the design page you point to : WebApplication1.ProductInfoCRUD
On the call to jquery you point to jqueryGridViewCrudOperations.aspx
and on the vb code server you point to productInfoCRUD :)
Hope this help :)
Friday, November 13, 2015 6:20 AM -
User368742804 posted
Thanks for responding
Friday, November 13, 2015 8:45 AM -
User368742804 posted
Thanks for the link
Friday, November 13, 2015 8:51 AM