c# mvc3 not showing jquery element after deployment - c#

When I am deploying my solution to my hoster a specific jquery element is just not showing up..
Its showing when i run it on my local pc.. but when deployed it just isnt there.. its a jquery element that renders a menu..
any ideas what could be causing this ?
I've uploaded all the references and everything..
jQuery.ajax({ type: "POST",
url: "/Bubble/MyInterests",
dataType: "json",
traditional: true,
success: function (data) {
$("#coInterestContainer").empty();
$("#coInterestTemplate").render(data).appendTo("#coInterestContainer");
$(document).on('click', '.coInterest', function () {
location.href="/Bubble/View/" + $(this).attr("id") + "?CreateOffer=1";
});
}
});

Related

how to handle multiple jqgrid instances on same page with ashx file ASP.NET

I'm using Webform and Jqgrid to display master-detail information on same page.
Here is my Jqgrid definition:
Master JQGrid:
$("#MachineListGrid").jqGrid({
url: 'AdminHandler.ashx',
datatype: "json",
...
});
Detail JQGrid:
$("#MachineDetailListGrid").jqGrid({
url:'AdminHandler.ashx',
datatype: "json",
...
});
my question is, how does ashx file identify data to return json data back to the correct jqgrid?
I'd looked at the same between aspx and ashx from this tutorial but the tutorial only gave sample one JQGrid on page.
on the code, here is the way to capture the request:
System.Collections.Specialized.NameValueCollection forms = context.Request.Form;
The way that will solve the problem is to have two url - one for the master and another for the detail
$("#MachineListGrid").jqGrid({
url: 'AdminHandlerMaster.ashx',
datatype: "json",
...
});
$("#MachineDetailListGrid").jqGrid({
url:'AdminHandlerDatil.ashx',
datatype: "json",
...
});
If you can't do this you may identify it with additional parameter in the post data something like this
$("#MachineListGrid").jqGrid({
url: 'AdminHandler.ashx',
datatype: "json",
postData : { gridtype:"master"},
...
});
$("#MachineDetailListGrid").jqGrid({
url:'AdminHandler.ashx',
datatype: "json",
postData : { gridtype:"detail"},
...
});
In the response you will need to get the gridtype parameter to identify the master and detail data

Consume ASP .Net WebService using HTML AJAX

I am trying to call a simple hellowworld function of ASP .NET WebService using JQuery AJAX call written in separate HTML file i.e. Not aspx file in ASP .NET.
Here is code of my AJAX call which works fine in aspx based web client.
$.ajax({
type: "POST",
url: "/Test1/RSSReader.asmx/GetRSSReader",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#output").text(msg.d);
},
error: function (e) {
$("#output").html("WebSerivce error " + e.responseText);
}
});
I want to call same webservice and same method using .html file but it is returning error. I tried giving server address i.e. localhost but still no response.

Loading JSON data from a file

This may be a duplicate of any question but I was not able to find a solution to my problem.
I am building an MVC4 application in which I want to load JSON data from another JavaScript file, using AJAX.
For this, I tried using $.getJSON(), $.ajax(), $.get() other similar functions to load data. It is a simple AJAX call, nothing fancy! Eventually I realized that I need to make this call to a controller/action which would load the JSON and return it back. This solution worked for me.
$.ajax({
type: "GET",
url: "/controller/action", // <-- How can I refer to the JSON file directly here?
contentType: "application/json; charset=utf-8",
dataType: "application/json",
success: function(data) {
},
error: function(err) {
}
});
I want to know if there is some other way for me to load this file using JavaScript in the view itself without invoking any controller/action?
Note: The file is a .json file and not a .js file. I don't want to include the file in any <script> tag!
The problem here is that you don't have a mime type of type json specified in your web.config and IIS/IIS Express is returning a 404 error.
Try modifying your web.config like so:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
You will also need to change the dataType to json instead of application/json:
$.ajax({
type: "GET",
url: "Content/your.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
},
error: function (err) {
}
});
Hope this helps.
To refer a JSON file, you can use the Url.Content() method in your Javascript :
$.ajax({
type: "GET",
url: "#Url.Content("~/Content/your.json")",
contentType: "application/json; charset=utf-8",
dataType: "application/json",
success: function (data) {
},
error: function (err) {
}
});
In this case, I have a your.json file in Content folder.
Hope it helps !

WebMethod called through Jquery Ajax is doing 301 redirect

I have a webmethod in aspx page and I am calling it through jquery Ajax method.
In one server I am getting windows security prompt on ajax call (all other servers are working fine).
When I was checking using fiddler I see a 301 redirect of my method call(webmethods.aspx/GetDetails to webmethods.aspx/GetDetails/)
Not sure why the redirect is happening on one server and call to webmethod.aspx/GetDetails/ is throwing 401.
I checked all the wildcard mapping etc and not able to find any issues. Any idea where else I need to check?
Here is my code
$.ajax({
type: "POST",
url: "/webmethods.aspx/GetDetails",
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
//alert('success');
},
failure: function (response) {
alert(response);
},
error: function (jqXHR, textStatus, errorThrown) {
var errMessage = "An error occured serving your request. Please try again.";
if (jqXHR)
errMessage = $.parseJSON(jqXHR.responseText).Message;
alert(errMessage);
}
Can you check the handler order in your web.config? I have had similar issue where staticfile handler was before aspx handler. Changing the order fixed my issue (move the static file as the last element, because most of the time it will have verify whether file exists before handling).

unable to render Json string on client side

ascx.cs
protected string BindData()
{
List<Product> products = product.GetRepeaterData(prod);
string json = JsonConvert.SerializeObject(products);
return json;
}
ascx
<script type="text/javascript" language="javascript">
function doSomething() {
$.ajax({
type: "POST",
url: "/ProgramListSimple.aspx/BindData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
});
};
I am not able to see any alert ..I dont know if the ajax function is doing what it is suppose to do..this code is for user control & not on the aspx page does that matter? while debugging I am able to see the serialized data in json string. Its just that its not rendering on the client side....working on it since morning now I need some help please..any examples or any doc can also be useful..
You have to use the d property
alert(msg.d);
If you are using Chrome or Firefox to debug use the following to inspect a JavaScript object:
console.log("%o", msg);
In Chrome press Ctrl + Shift + J to show the developer console
I created a new aspx page. Transfered all the code behind logic to the aspx.cs from ascx.cs. The just called the url of the aspx page from my ascx page using ajax callback
type: "GET",
url:'<%=VirtualPathUtility.ToAbsolute("~/ProgramListSimpledetail.aspx") %>',
data: dataObject,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
I just added a small part of the fix that is very important for this to work other then this there were bunch of things that were added to make the ascx page inherit the properties from the apsx page.... but I think that was mainly related to my code...so I hope this helps someone in future...thanks for all those who tried to contribute..

Categories