Hi Community Fairly new to Laravel and wanted to know how I would update Laravels Pagination in Javascript. If that is at all possible and how to go about it
This is My Route:
Route::get('/vehicles/search/{make}/{model}/{type}/{yearf}/{yeart}/{minp}/{maxp}', 'VehiclesController#searchVehicle');
My Controller:
public function searchVehicle($make,$model,$type,$yearf,$yeart,$minp,$maxp)
{
$results = Vehicles::where('make', 'LIKE', '%'.$make. '%')->orWhere('model','LIKE', '%'.$model.'%')->paginate(2);
return($results);
}
And my JS:
var strUrl = vehicle_url + "search/" + vmake + "/" + vmodel + "/" + yearfrom + "/" + yearto + "/" + type + "/" + minprice + "/" + maxprice;
var obj = sendRequest(strUrl);
It would be updating my laravel pagination which would be:
{{$all->links}}
Related
I have the follwoing Jquery code to open page on button click passing a parameter but ? is translated to %3F is there anyways to fix this?
$("#PrintDocument").click(function () {
var grid = $("#Billings").data("kendoGrid");
var row = $("input:checked", grid.tbody).closest("tr");
var item = grid.dataItem(row);
window.location.pathname = '/invoice/billing/Print' + '?productId=' + item.ProductID + '&' + 'runId=' + item.RunID;
});
You are setting the pathname which does not have a query string.
window.location.href = '/invoice/billing/Print' + '?productId=' + item.ProductID + '&' + 'runId=' + item.RunID;
I am working on twitter integration. I am using CryptoJs to create a signature. Here is the code.
The issue is, following code is working without "in_reply_to_status_id" parameter, but with that parameter it is giving "could not authenticate issue".
var autSign =
'oauth_consumer_key=' + percentEncode(consumer_key) + '&' +
'oauth_nonce=' + percentEncode(nonce) + '&' +
'oauth_signature_method=HMAC-SHA1&' +
'oauth_timestamp=' + timeStamp + '&' +
'oauth_token=' + percentEncode(access_token) + '&' +
'oauth_version=1.0&status=test3&in_reply_to_status_id=1217119832744898564';
var baseString =
"POST&" +
percentEncode(endpoint) + "&" + percentEncode(autSign);
var signingKey = this.percentEncode(consumer_secret) +
"&" + this.percentEncode(access_token_secret);
var encrypted = CryptoJS.HmacSHA1(baseString, signingKey);
var signature = CryptoJS.enc.Base64.stringify(encrypted);
How to send encode string as a parameter into URL string in angular and open in new tab. I am trying to send multiple parameter separated by '-' and converted into base64 encode through url but it is throwing me into not found. I am using angular 8. using router.navigate , it is working fine but I want to open url in new tab.
here is my code in TS.
goToAssessmentPage(event, assignmentId, courseId, studentId, instituteId, sectionId , assignment_submission_id) {
event.preventDefault()
const string:string = btoa(courseId + '-' + assignmentId + '-' + studentId + '-' + instituteId + '-' + sectionId + '-' + assignment_submission_id)
const url: string = string + '/grader-assessment';
window.open(url, '_blank');
}
app.routing.ts
{
path: ':params/grader-assessment',
component: GraderAssessmentPageComponent
},
Well you'll more than likely need the whole url tree in that url string for window.open to work.
From the docs (https://angular.io/api/router/Router#createurltree)
// create /team/33/user/11
router.createUrlTree(['/team', 33, 'user', 11]);
And on top of that (https://angular.io/api/router/Router#serializeurl)
serializeUrl(url: UrlTree): string
So in your case it would be something like:
const string:string = btoa(courseId + '-' + assignmentId + '-' + studentId + '-' + instituteId + '-' + sectionId + '-' + assignment_submission_id)
const fullUrl:string = this.router.serializeUrl(router.createUrlTree([string, '/grader-assessment']));
// Then you navigate to this full url
window.open(fullUrl, '_blank');
Is this the optimal way to load form data into a string and then to localStorage ?
I came up with this on my own, and I am not good in programming. It works, for what I need, but I am not sure if it's a bulletproof code?
<script>
var sg = document.getElementById("selectedGateway");
var sd = document.getElementById("selectedDestination");
var dm = document.getElementById("departureMonth");
var dd = document.getElementById("departureDay");
var dy = document.getElementById("departureYear");
var rm = document.getElementById("returnMonth");
var rd = document.getElementById("returnDay");
var ry = document.getElementById("returnYear");
var ad = document.getElementById("adults");
var ch = document.getElementById("option2");
$("#searchRequestForm").submit(function() {
var string = 'From: ' + sg.value + ' \nTo: ' + sd.value + ' \nDeparture: ' + dm.value + '/' + dd.value + '/' + dy.value + ' \nReturn: ' + rm.value + '/' + rd.value + '/' + ry.value + ' \nNumber of adults: ' + ad.value + ' \nNumber of children: ' + ch.value;
localStorage.setItem("string", string);
});
</script>
I would use something like the following so that I could deal with an object and its properties rather than a big string. Note that other than the jQuery selectors, this is pure JavaScript.
Demo: http://jsfiddle.net/grTWc/1/
var data = {
sg: $("#selectedGateway").val(),
sd: $("#selectedDestination").val()
// items here
};
localStorage.setItem("mykey", JSON.stringify(data));
To retrieve the data:
var data = JSON.parse(localStorage["mykey"]);
alert(data.sg);
See Also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify
http://api.jquery.com/jQuery.parseJSON/
I prefer a table driven approach so there is no repeated code (DRY):
var ids = [
"selectedGateway", "From: ",
"selectedDestination", "\nTo :",
"departureMonth", "\nDeparture: ",
"departureDay", "/",
"departureYear", "/",
"returnMonth", " \nReturn: ",
"returnDay", "/",
"returnYear", "/",
"adults", " \nNumber of adults: ",
"option2", " \nNumber of children: "];
var submitStr = "";
for (var i = 0; i < ids.length; i+=2) {
submitStr += ids[i+1] + document.getElementById(ids[i]).value;
}
localStorage.setItem("string", submitStr);
You could define a function such as the one below to directly get the values by id so then it would be simpler when you build your string.
function form(id) {
return document.getElementById(id).value;
}
Here are some strings that I'm using to ultimately form a HTML mailto link. I'm doing this in javascript. If I output the mailtoString to an alert() I get the link looks just fine. However, when I put it into the location.href the string is cut short at the "&" character. How do I tell the location.href that the "&" is not the end of the mailto link?
var subject = escape('subject');
var body = escape('body');
var reportUrl = document.URL + "/GetUpdatedTableResults?beginDate=" + beginDate + "&endDate=" + endDate + "&fileId=" + DocId + '&languageCode=' + LangCode + '&documentResultType=' + result + '&result=' + ReportedIssue;
var excelUrl = document.URL + 'CurReport/GetCSVReport?beginDate=' + beginDate + '&endDate=' + endDate + '&fileId=' + DocId + '&languageCode=' + LangCode + '&documentResultType=' + result + '&result=' + ReportedIssue;
var mailtoString = 'mailto:?subject=' + subject + '&body=' + body + '%0A%0AWeb:%0A' + reportUrl + '%0A%0AExcel:%0A' + excelUrl;
location.href = mailtoString;
After running the code above I get the following output.
http://localhost:5050/CurReport/GetUpdatedTableResults?beginDate=0
Because immediately after mailto: should be the email address. ? is a valid email characters but & is not. Anyway, the & should be escaped to &.