Hi,
In my code behind file, I called Soap web reference and retreive data and diplay in grid view and it worked. But when I convert retreived data to Json text and send back to java script and on client side, convert json text to java script object and when try to display it, its displaying nothing. I dont know if i m doing something wrong here. please check my code and give me suggestions, I really need help.
Below is the javascript file:
$.ajaxSetup({
cache: false,
timeout: 5000
});
var ajax_load = "<img src='loading.gif' alt='loading...' />";
// load() functions
var loadUrl = "test.txt";
var the_object = {};
function concatObject(obj) {
str = '';
for (prop in obj) {
str += prop + " value :" + obj[prop] + "\n";
}
return (str);
}
$(document).ready(function() {
$("button").ajaxStart(function() {
alert('Triggered ajaxStart handler.');
});
$("button").click(function() {
$.ajax({
type: "POST",
dataType: 'JSON',
url: "Testing.aspx/SendMessage",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
success: function(result, txtStatus, httpRequest) {
alert("success");
the_object = httpRequest.responseText;
}
});
//alert(concatObject(the_object));
$('#result').html(concatObject(the_object));
});
});
and here is code behind file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
using System.Data;
using System.Text;
using System.IO;
using Newtonsoft.Json;
public partial class Testing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//al2c00.ldap lp = new al2c00.ldap();
//DataTable dt = lp.GetEmployeeDetailsBy_NTID("650FA25C-9561-430B-B757-835D043EA5E5", "stephen.gilroy1");
//GridView1.DataSource = dt;
//GridView1.DataBind();
}
public static string SendMessage()
{
al2c00.ldap lp = new al2c00.ldap();
return JavaScriptConvert.SerializeObject(lp.GetEmployeeDetailsBy_NTID("auth_code", "amby"));
}
}
and below is the main file:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testing.aspx.cs" Inherits="Testing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery.js" type="text/javascript"></script>
<script src="Testing.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
Employee's NTID: <input type="text" id = "Eid" name="Employee_NTID" />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
<br />
<button type = "button" id = "callingMethod">Search</button>
<p id = "result"></p>
</div>
</form>
</body>
</html>