I'm really struggling with getting the percentage value of progress that is continuously being updated in a function on my controller to appear in template GSP page using remoteFunction.
This is my controller code and "progressData" is sent from a service to constantly update the current progress of a task:
def progress(progressData) {
def statusToView = progressData
[statusToView: statusToView]
}
and in my _progress.gsp page:
<g:javascript>
setInterval( "refreshMe();", 300 );
function refreshMe(){
${remoteFunction(action:'progress', controller:'data')}
}
</g:javascript>
The controller is expecting the property progressData which is doesn't get from the remoteFunction, and so I'm guessing I have to think to do this another way but I'm just at a bit of a loss now. Plus I'm not getting the value statusToView within the GSP because of this.
As you pointed out, your action progress is actually waiting for the progressData param, which is not passed.
If your progressData value is stored somewhere in your gsp page, you should change your remoteFunction in this way or similar:
$remoteFunction(action: 'progress', controller: 'data', update: [success: 'great', failure: 'ohno'], params: '\'progressData=\' + progressData')
Regarding update: [success: ... ], here you can find the description of the various attributes.
Related
I am working on a project built in ASP.Net MVC 3.
In the index page I have displayed the data and allow the user to do inline editing using jeditable (which also uses ajax function) and delete function.
In the create page, obviously it allows the user to enter new the data but now I need to add a feature to allow the delete from the create page itself if the data already exists on the database.
Shows confirmation box if the data already exists (in my case if Extension is not available) on Extension's textbox blur.
I was using the ajax function for this feature but was not working, after spending hours on it, I was able to figure out the what was causing the problem.
The ajax function was working only on the Index page, not the other page. I renamed the Create page as Index and the original Index to something else, well it worked this time but ajax stopped working on the original Index page which was renamed to something else.
In the url if I load the index page as "http://localhost:1234/Controller/Index", the page loads fine but ajax functions do not work.
In a simple way:
Ajax functions works on
localhost:1234/Controller
Ajax functions do not work on
localhost:1234/Controller/Create
localhost:1234/Controller/ViewPage1
localhost:1234/Controller/Index
If someone could explain why its behaving like this, it would be great to have solution for this and whats the alternative solution for this if it can be fixed.
Thanks
Javascript code
$('#Extension').blur(function () {
$.post("CheckPeople/checkDelete",
{
Extension: this.value
},
function (data) {
alert(data);
});
});
Controller: VB Code
//GET: /People/
Function Index() As ViewResult
ViewBag.CurrentPage = "People"
Return View(db.Peoples.ToList())
End Function
//GET: /People/Create
Function Create() As ViewResult
Return View()
End Function
//POST: /People/Create
<HttpPost()>
Function Create(ByVal people As People) As ActionResult
If ModelState.IsValid Then
db.Peoples.Add(people)
db.SaveChanges()
Return RedirectToAction("Index")
End If
Return View(people)
End Function
Public Function checkDelete(ByVal Extension As String) As JsonResult
Dim result As String = "I got you "
Return Json(result, JsonRequestBehavior.AllowGet)
End Function
Thanks for the comments, I added the code, its straight forward.
If I rename the Create.vbhtml to Index.vbhtml and commented the original Index routing and rename both post and get Create routing to Index, ajax works fine.
I think its a relative url issue.
try adding a / in front of the ajax request url, like
$.post("/CheckPeople/checkDelete",
{
Extension: this.value
},
function (data) {
alert(data);
});
});
hope this helps.
This is probably one very simple question to answer, but I can't output the variable I am trying to send to a view through a controller in the Grails Framework.
render(view: 'parseerror', error: it)
That's my code in my controller, it renders the view correctly but as soon as I am trying to call the variable through ${error} it outputs nothing. It should output a string since when I print the iterator, the console output: The example string
Thanks for helping me out :)
The map key is "errors", not "error", but I belive, you want to achieve something similar to this code:
render( view: 'parseerror', model: [ 'error': error ] )
I have a controller that has an ajax function and a seperate action that redirects the page. I want to know is it possible to make the ajax call when the link is clicked, but wait for the function to finish before the redirect action is called?
E.g.
<g:link controller="myController" action="myRedirectAction" before="saveData">link</g:link>
EDIT Added code
controller
def ajx_saveServiceGroup = {
//Code to save data to object
return
}
def saveConfigToRoLo = {
//code to save object to DB
redirect(action:"displayPDFSummary", id:orderId, params: [origSessionId: params.origSessionId, theSession: tempSession])
}
gsp
<g:link class="buttonSend" action="saveConfigToRoLo" id="${orderDataInstance.id}" params="[origSessionId: origSessionId, orderId: orderDataInstance.id, submitToBT: true]" before="ajx_saveServiceGroup">Submit</g:link>
you can have a remoteLink and then onSuccess callback you can change the windows.location to whatever you want !
A details description of what you are trying to achieve will help us provide better answers.
I'm using Fancybox 1.3.4 with ASP.NET MVC 3.
I have following link :
<a id="various" href="Like/List/#feed.Id" class="petlikeCount liked">#feed.LikeCount</a>
and also jquery :
<script type="text/javascript">
$(document).ready(function () {
$("#various").fancybox({
type: 'ajax'
});
});
</script>
Controller action in Like controller :
public JsonResult List(int id)
{
return Json("success", JsonRequestBehavior.AllowGet);
}
My problem is that Like/List is never called (checked with the breakpoint) and fancybox just appears and show content of "parent" page....
I also tried with iframe content returning pure html back, but I'm getting same strange behavior as above.
Thank you in advance!
I'd recommend you using HTML helpers instead of hardcoding anchors:
#Html.ActionLink(
feed.LikeCount,
"List",
"Like",
new { id = feed.Id },
new { id = "various", #class = "petlikeCount liked" }
)
Another thing that you should make sure is that the feed.Id is actually an integer variable so that when the List action is invoked it is correctly passed this id.
So your url should look something like this: /List/Like/123. And then assuming tat you have kept the default route and haven't messed up with some custom routes, the List action should be called and passed the correct id as argument.
Also I would very strongly recommend you using a javascript debugging tool in your browser such as FireBug in which you will be able to see any potential errors with your scripts as well as the actual AJAX requests being sent which will allow you to more easily debug such problems.
I have defined an action on my controller which accepts an integer and returns a string value:
public string SqlQuery(int listItemId)
{
return _sqlListSharePointList.GetSqlQueryFromCache(listItemId);
}
How could I call this action from my view? also what other options do I have apart from AJAX?
I tried the below but didn't work:
$.get('/SqlReportList/SqlQuery', 1, function (data) {
alert(data);
});
the "SqlReportList" is the name of my controller.
I also tried the below code:
$.get('/SqlReportList/SqlQuery/1', function (data) {
alert(data);
});
But it threw an exception on production that the listItemId is null.
Should I decorate my Action differently?
I also tried accessing it via fully qualified name but same error:
http://localhost:4574/SqlReportList/SqlQuery/1
Thanks,
If you do not want to use ajax (which is recommended) then only way to call the method is thru page refresh, only that way you are hitting your server side (controller) again from the view.
$.get('/SqlReportList/SqlQuery', { "listItemId": listItemId }, function (data) {
$('#tbSqlQuery').text(data); }
);
Is the parameter known at the time of rendering the surrounding page?
If so (and I've understood your question correctly) then you can use Html.RenderAction. See http://haacked.com/archive/2009/11/17/aspnetmvc2-render-action.aspx
If not, then you can only really use AJAX or a full page reload. For getting the URL right for AJAX, you should be able to use Url.Action with some placeholder value.
The T4MVC project offers strongly-typed support for various things including action URLs, even supporting explicit placeholders for Javascript code. See section 2.2.2 of http://t4mvc.codeplex.com/documentation