Change route running - visual-studio-2013

I've created this route: Home / PaginaBase.
This route is called a new page, called PaginaBase, which has a similar header and footer Index. This creates a footer menu.
When I select an item from this menu, he calls me PaginaBase riding a URL like this:
http://www.localhost:58686/Home/PaginaBase/6/3.
Until then, it's ok. When I select another item (PaginaBase still inside), it retains the same URL in the call and adds Home/PaginaBase/8/3 again, there is a non-existent route.
How do I solve this?
Below is my jquery function.
function MontaMenuInferior() {
var str = "";
$.ajax({
url: '/Home/MontaMenuInferior',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
success: function (data) {
$(data.resultado).each(function () {
str = str + '<ul class="grid_4">' +
'<li>' + this.SubCategoria + '</li>';
$(this.subconsulta).each(function () {
if (this.Id_SubCategoria2 != null)
str = str + '<li>' + this.SubCategoria2 + '</li>';
//str = str + '<li>this.SubCategoria2 + ''
else
str = str + '<li>' + this.SubCategoria2 + '</li>';
});
str = str + '</ul>';
$('#menufooter').append(str);
str = "";
});
},
error: function (error) {
}
});
}

You're using relative URLs in your links. If you're in /Home/PaginaBase/6/3 (i.e. that's your path) and you click a link to Home/PaginaBase/8/3 your new path will be /Home/PaginaBase/6/3/Home/PaginaBase/8/3.
Using absolute URLs will replace your path instead of appending to it: /Home/PaginaBase/8/3 (notice the / in the beginning).

Related

i could not get the data in my showdata div

I want the list all the details from tow tables using single id without refreshing the Page using Ajax
This is my button and div:-
<button id="brand" data-b_id="21">brand</button>
<div id="#showdata"></div>##
This is my javascript:-
$('#brand').click(function() {
show_product();
function show_product() {
var b_id = $('#brand').data('b_id');
//alert(bid);
$.ajax({
type: 'POST',
url: '<?php echo base_url('index.php/Airtel/get_bdid')?>',
dataType: 'JSON',
data: {
b_id: b_id
},
success: function(data) {
var html = '';
var i;
for (i = 0; i < data; i++) {
html += '<tr>' +
'<td>' + data[i].b_name + '</td>' +
'<td>' + data[i].d_name + '</td>' +
'<td>' + data[i].d_id + '</td>';
};
$('#showdata').html(html);
}
});
}
});
This is my controller:-
public function get_bdid(){
$b_id=$this->input->post('b_id');
$data=$this->mymod->get_bdid($b_id);
echo json_encode($data);
}
This is my model:-
public function get_bdid($b_id){
$this->db->where('b_id',$b_id);
$this->db->select('*');
$this->db->from('brand');
$this->db->join('dth', 'dth.b_name = brand.b_name');
$query = $this->db->get();
return $query->result();
}
Perhaps, there are many errors in browser developer mode.
plz Check your javascript
success: function(data) {
console.log(data);
}
"get_bdid" controller is retrun "json" data type
success: function(data) {
var obj = JSON.parse(data);
console.log(obj);
// or loop
}

My jquery and ajax call is not responding and showing unexpected error in console

I don't know why my code is giving error while making the ajax call and not responding or working at all. I ran this on an html file. I took this function - getParameterByName() from another stackoverflow answer.tweet-container tag is down the code below outside this script and an empty division.I tried some jquery also.
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function(){
console.log("working");
var query = getParameterByName("q")
// console.log("query");
var tweetList = [];
function parseTweets(){
if (tweetList == 0){
$("#tweet-container").text("No tweets currently found.")
} else {
//tweets are existing, so parse and display them
$.each(parseTweets, function(key, value){
//console.log(key)
// console.log(value.user)
// console.log(value.content)
var tweetKey = value.key;
var tweetUser = value.user;
var tweetContent = value.content;
$("#tweet-container").append(
"<div class=\"media\"><div class=\"media-body\">" + tweetContent + "</br> via " + tweetUser.username + " | " + View + "</div></div><hr/>"
)
})
}
}
$.ajax({
url:"/api/tweet/",
data:{
"q": query
},
method: "GET",
success:function(data){
//console.log(data)
tweetList = data
parseTweets()
},
error:
function(data){
console.log("error")
console.log(data)
}
})
});
</script>
strong text
Fix the quotes to resolve your syntax error:
$("#tweet-container").append("<div class=\"media\"><div class=\"media-body\">" + tweetContent + " </br> via " + tweetUser.username + " | " + "View</div></div><hr/>")

how ajax site wide browsing works on phpfox?

i'm trying to use ajax wide browsing on phpfox but i dont understand how it works,
any idea please ?
i found in static/jscript/main.js this code :
$Core.ajax = function(sCall, $oParams)
{
var sParams = '&' + getParam('sGlobalTokenName') + '[ajax]=true&' + getParam('sGlobalTokenName') + '[call]=' + sCall;
if (!sParams.match(/\[security_token\]/i))
{
sParams += '&' + getParam('sGlobalTokenName') + '[security_token]=' + oCore['log.security_token'];
}
if (isset($oParams['params']))
{
if (typeof($oParams['params']) == 'string')
{
sParams += $oParams['params'];
}
else
{
$.each($oParams['params'], function($sKey, $sValue)
{
sParams += '&' + $sKey + '=' + encodeURIComponent($sValue) + '';
});
}
}
$.ajax(
{
type: (isset($oParams['type']) ? $oParams['type'] : 'GET'),
url: getParam('sJsStatic') + "ajax.php",
dataType: 'html',
data: sParams,
success: $oParams['success']
});
};
I'm trying to fix a module of chat while browsing on my site
Any idea plz ?
To make a link for site wide ajax browsing you do it just like usual, phpfox will figure it out for you.
If you want to make an ajax call in phpfox you do:
$.ajaxCall('module.function', 'param1=value1&param2=value2');
for example:
$.ajaxCall('ad.recalculate', 'total=' + iTotal + '&location=' + sLocation + '&block_id=' + sBlockId + '&isCPM=' + $Core.Ad.isCPM);
Calls the function recalculate in the file /module/ad/include/component/ajax/ajax.class.php and passes the params: total, location, block_id and isCPM

CFWheels Pagination using AJAX

I've searched the entire Internet, all of it, and cannot find an answer to this.
I'm using the ColdFusion CFWheels Framework to query a database. The query is done via AJAX like this:
var id = $("#ship-id").val();
$.ajax({
type: "POST",
url: "/my-controller/my-method?format=json",
data: {shipId: id},
dataType: "json",
success: function(response) {
var resultHtml = '';
$.each(response, function(i, value) {
resultHtml += '<tr><td>' + value.FIRSTNAME + ' ' + value.LASTNAME + '</td></tr>';
});
$("#my-table").html(resultHtml);
}
});
I need to paginate that result set. In CFWheels you normally do that by setting the handle, page, perPage and order values in the query like this:
var order = model("order").findAll(
select="id, firstname, lastname, email",
where="orderid IN (#ValueList(orders.id)#)",
handle="ordersQuery",
page=params.page,
perPage=5,
order="lastname"
);
Then you just put this line in your view:
<cfoutput>#paginationLinks(handle="ordersQuery")#</cfoutput>
But... how in the heck can you get pagination to work with an AJAX call?
I think that something along these lines might be your answer (notice I removed the url and added those params to data ...
$.ajax({
type: "POST",
data: {
shipId: id,
controller: myController,
action: myAction,
page: params.page,
},
dataType: "json",
success: function(response) {
var resultHtml = '';
$.each(response, function(i, value) {
resultHtml += '<tr><td>' + value.FIRSTNAME + ' ' + value.LASTNAME + '</td></tr>';
});
$("#my-table").html(resultHtml);
}
});

AJAX call to Justin TV API failing with JSON format

I'm trying to make a simple AJAX call to the Justin TV API, which seems to be failing consistently.
When making the AJAX call with url1, the console reports Object { readyState=4, status=200, statusText="success"}, yet it falls into the error function of the AJAX call. When visiting the URL with my browser, I notice the returned data is [{ ... json ...}].
When making the AJAX call with 'url', the call passes, entering the success function. I notice the returned object is { ...json... }.
How do I get a valid JSON object out of the AJAX request for url1?
Here's a snip of what I'm doing:
var url1 = "http://api.justin.tv/api/stream/list.json"
var url = "https://api.twitch.tv/kraken/streams/";
channelNames = "";
for (channelName in streams)
{
channelNames = channelNames + ',' + channelName;
}
channelNames = channelNames.slice(1);
console.log(channelNames);
console.log(url1);
$.ajax({
url: url1,
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
data: { channel : channelNames },
success: function(data)
{
console.log(data);
if(data.streams.length > 0)
{
$("#streamStatus").html("<ul class='zebra'>");
for(i = 0; i < data.streams.length; i++)
{
stream = data.streams[i];
channel = data.streams[i].channel;
listItem = "<li id='stream"+i+"'>";
streamName = "<span class='name'>" + streams[stream.name.slice(10)] + "</span>";
viewers = "<span class='viewers'>viewers:" + stream.viewers + "</span>";
gameName = "<div class='game'>" + ((channel.game != null) ? channel.game : "No Game Specified") + "</div>";
listItem += streamName + viewers + gameName + "</li>";
screenCap = "<div class='screenCap' style='display:none;'>" + channel.screen_cap_url_small + "</div>"
$("#streamStatus ul.zebra").append(listItem);
$("#streamStatus ul.zebra").append(screenCap);
//console.log(channel);
}
$("#streamStatus").append("</ul>");
}
},
error: function(data)
{
console.log(data);
}
EDIT: Here is the working solution...
var url1 = "http://api.justin.tv/api/stream/list.json"
var url = "https://api.twitch.tv/kraken/streams/";
channelNames = "";
for (channelName in streams)
{
channelNames = channelNames + ',' + channelName;
}
channelNames = channelNames.slice(1);
console.log(channelNames);
console.log(url1);
$.ajax({
url: url1,
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
jsonp: 'jsonp',
data: { channel : channelNames },
success: function(data)
{
...
},
error: function(data)
{
console.log(data);
}
You're passing jsonp as the dataType in the ajax call. They're not interchangeable.
As you've noted yourself, the data returned from url1 is JSON, not JSONP: JSONP requires wrapping the returned JSON data in a javascript function call.
A mismatch like this between dataType and the data in the response body will always cause the ajax call to fail.

Resources