logo
down
shadow

Partial refresh in ASP using ajax


Partial refresh in ASP using ajax

By : Supi Core
Date : November 22 2020, 02:42 PM
Hope this helps Since you are making an $.post() you need to decorate your /UpdateTest/Run action with [HttpPost].
You also don't define a success handler so, while you are making the request, you never do anything with it.
code :
$.post("/UpdateTest/Run", { input: NAME })
    .done(function(partialResult) {
        $("#log").html(partialResult);
    })
    .fail(function(jqxhr, status, error) {
        console.log(jqXhr, status, error);
    });


Share : facebook icon twitter icon
Is it possible to refresh partial frequently using Ajax?

Is it possible to refresh partial frequently using Ajax?


By : Killian H
Date : March 29 2020, 07:55 AM
wish of those help In background, I want it to reload and shows the number how many unread messages are there. , You will use setInterval to send the ajax request:
code :
$(document).ready(function () {
    // will call refreshPartial every 3 seconds
    setInterval(refreshPartial, 3000)

});

// calls action refreshing the partial
function refreshPartial() {
  $.ajax({
    url: "whatever_controller/refresh_part"
 })
}
def refresh_part
  # get whatever data you need to a variable named @data
  respond_to do |format|
    format.js
  end
end
$('#part_you_want_to_refresh').html("#{escape_javascript(render 'name_of_partial', data: @data)}");
What is the alternative of ajax.beginform and unobtrusive-ajax.js for partial refresh?

What is the alternative of ajax.beginform and unobtrusive-ajax.js for partial refresh?


By : ugv
Date : March 29 2020, 07:55 AM
wish of those help I'm using both Ajax.BeginForm and jQuery 1.9, and they work perfectly.
Have you set the UpdateTargetId property in your AjaxOptions? This is what I have (I could use a model, but I'm simplifying the example):
code :
@using(Ajax.BeginForm("Index", "Search",
  new AjaxOptions(){ UpdateTargetId = "result"})
{
    <input type="text" name="q" />
    <button type="submit">Send</button>
}

<div id="result"></div>
@using(Ajax.BeginForm("Index", "Search", null,
    new AjaxOptions(){ UpdateTargetId = "result"},
    new { @class = "myFormClass", name = "myForm" } )
Not able to refresh the partial view after a form submission from another partial view within it, using ajax in mvc razo

Not able to refresh the partial view after a form submission from another partial view within it, using ajax in mvc razo


By : user2842614
Date : March 29 2020, 07:55 AM
should help you out Your Ajax.BeginForm() is replacing the contents of
with the html from return PartialView("_posts", msgDetails);. I suspect the model msgDetails contains only the details of the comment's associated message so that's all your seeing.
I suggest to rethink your design, particularly the Messages() method, which after saving the message is calling the database to get all messages and returning the complete list - you already have all the data on the page so this seems completely unnecessary and just degrades performance. You could simplify it with the following
code :
@model Model.Message
<div class="message">
  <div class=username">@Model.UserName</div>
  <div class=messagetext">@Model.MessageText</div>
  <div class="commentlist">
    @foreach (var comment in Model.Comments)
    {
      <div class="comment">
        <div class="username">@comment.UserName<div>
        <div class="commenttext">@comment.MessageText<div>
      </div>
    }
  </div>
  <div>
    @Html.TextBox("CommentText", new { placeholder = "Leave a comment", id = "" }) // remove the id attribute so its not invalid html
    <button class="addcomment" data-id="@Model.MessageId">Add Comment</button>
  </div>
</div>
@model myModel
...
@Html.TextArea("Message", new { placeholder = "Add a post" })  // no point adding the id - its already added for you    
<input type="button" id="Post" value="Post" />
<div id="messagelist">
  @foreach(var message in Model.MessageList)
  {
    @{ Html.RenderPartial("_posts", message); }
  }
</div>
<div id="newmessage"> // style this as hidden
  @{ Html.RenderPartial("_posts"); }
</div>
// Add a model or ViewBag property for the current user name
var userName = JSON.parse('@Html.Raw(Json.Encode(ViewBag.UserName))');

$('#Post').click(function () {
  var url = '@Url.Action("Message", "MyController")'; // dont hardcode!
  var message = $('#Message').val();
  $.post(url, { MessageText: message }, function (data) {
    if(data) {
      // clone the new message, update message id and add to DOM
      var html = $('#newmessage').clone();
      message.children('.username').text(userName);
      message.children('.messagetext').text(message);
      message.children('.newcomment').children('button').data('id', data);
      $('#messagelist').perpend(html); // add at top of list
      $('#Message').val(''); // clear message text
    } else {
      // something went wrong
    }
  });
});

$('.addcomment').click(function() {
  var url = '@Url.Action("Comment", "MyController")';
  var comment = $(this).prev('input');
  var messageID = $(this).data('id');
  var list = $(this).closest('.message').children('.commentlist');
  $.post(url, { MessageID: messageID, CommentText comment.val() }, function (data) {
    if (data) {
      // add message
      var html = $('<div><div>').addClass('comment');
      html.append($('<div><div>').addClass('username').text(userName));
      html.append($('<div><div>').addClass('commenttext').text(commentText));
      list.append(html); // add to end of existing comments
      comment.val(''); // clear existing text
    } else {
      // something went wrong
    }
  });
});
[HttpPost]
public ActionResult Message(string MessageText)
{
  // create new message object and save to database
  int ID = // the ID of the new message
  return Json(ID); // if exception, then return null;
}

[HttpPost]
public ActionResult Comment(int MessageID, string CommentText)
{
  // create new comment object and save to database
  return Json(true); // if exception, then return null;
}
Rails 5.1: refresh partial within partial with AJAX

Rails 5.1: refresh partial within partial with AJAX


By : Michael Looper
Date : March 29 2020, 07:55 AM
Does that help In update.js.erb, you have a typo. You should delete the %>. Try this:
code :
$('#userprofile').replaceWith('<%= j render (@user) %>')
$('#userprofile').html('<%= j render (@user) %>')
Ruby on Rails Partial won't refresh with AJAX but says it is rendering the partial in the console

Ruby on Rails Partial won't refresh with AJAX but says it is rendering the partial in the console


By : zhzhenqin
Date : March 29 2020, 07:55 AM
Hope that helps Your error seems simple
you are trying to change the html of the div with id 'boundbookstable'
code :
$("#boundbookstable").html(...
<table id="boundbooktable" border="1">
Related Posts Related Posts :
  • generate all web.config transformations at the same time to different files
  • Pass value to another page from image click in gridview
  • ASP.NET MVC: How to search decimal value?
  • ASP.NET Regular Expression Validator VS Required Field Validator OR both?
  • Combine SQL columns using case when appearing null
  • Asp.net mvc open form with default value in field
  • Auto Increment Reseed when another ID has been changed on Insert Query
  • The resource name is not a valid identifier for devexpress gridview
  • Razor htmlListBox helper
  • Trying to run a local website
  • How To Set dxn runtime to .net 4.6.1 with Rc1 - Final
  • How do I clear/reset date field when using jquery datepicker
  • Azure SQL Database sometimes unreachable from Azure Websites
  • Enabling Application Insights makes the Web App hang
  • Ajax-call refreshes page
  • Read from 2 sql datasource in asp.net
  • System.ArgumentNullException in Mono ASP.NET Web Service
  • what is response.write in asp.net mvc?
  • dnx kestrel "System.EntryPointNotFoundException: uv_loop_size"
  • How to display two partialviews in the same view in MVC?
  • Add custom columns on many to many relationship on NHibernate
  • System.Web.HttpException with "Type Service not found." in Mono ASP.NET Web Service
  • Object cannot be cast from DBNull to other types when password or username not found
  • Which process Visual Studio has to attach to run DNX process?
  • Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on t
  • VB.NET querystring has parameter
  • Cookies not deleted on logout
  • Check Checkboxes in a gridview based on a non-boolean value from a stored procedure
  • ASP.NET MVC: Getting unhandled exception that stops in a catch block of a rethrow
  • asp.net gridview - spread bound data across multi lines per row with updatepanel
  • Context menu doesn't contain Scaffolding VS2015 ASP.NET 5
  • IModelBinder in WebApi string manipulation
  • No authentication handler is configured to handle the scheme: Automatic
  • MVC 5 - how can I send a SelectList from a controller to a dropdownlist and show the data text field with more than one
  • Is WCF or Web API best for file upload using streams (large files) in a windows service (Self host, not IIS)
  • change a datafield in WebPartPages:DataFormWebPart
  • What are the valid DNX --watch flag values?
  • ASP.NET MVC Entry Point
  • Login Fail after moving database and website
  • How to Authenticate Login form without using asp controls
  • OnModelCreating undefined in Entity Framework 7
  • Unable to configure IIS/Asp.NET to process many asynchronous requests concurrently
  • ASP.Net Treeview check node exists
  • Asp.net URL Rewriting
  • Redirect to Controller action from an Async Controller action not working
  • ASP MVC Bootstrap-project - activate email-button
  • How to specify the destination for an existing ClaimsIdentity?
  • ActionLink ignoring attribute routing settings
  • How to write an api action to create an entity in Web API
  • Determine StyleSheetTheme based on page's master page in asp.net
  • asp.net passing an id between views in different controllers
  • Button visibility before and after session is called in VB
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co