Welcome Guest, Not a member yet? Register   Sign In
Jquery and CI, URL problems
#1

[eluser]piranha_swe[/eluser]
Hi!

I've been searching on this topic and found several posts but I haven't been able to figure out how to solve my problem from them.

I'm using jQuery to load a php page that keeps track of a shoppingcart. The jquery code looks like this:

function BuyRecord(id)
{
$("#cart").load("<?php echo $base;?>ajax/ajax_cart.php", { 'recordid':[id] });
}

The div with id=cart doesnt change so something is wrong.
Is there a problem with my load url? URLs are difficult for a CI noob :-).

Or do you have to treat things diffrent compared to when not using a framework? When dealing with javascript / jquery ?

Here is the url to the site if that will help.
http://www.vinylcatch.se/records/recordlist/house
#2

[eluser]jdfwarrior[/eluser]
Is that jQuery code a script that is defined inside the view file or a separate js file that it loaded from the view? Also, what is $base? I'm assuming thats your base_url() output somewhere else?
#3

[eluser]piranha_swe[/eluser]
I loading js files in a view (header) from jquerys page
http://jqueryui.com/latest/jquery-1.3.2.js


I decided to load from jquerys page to make sure that I got a working url.
$base is $base_url(); that I have in my controller, passing it to the view.
#4

[eluser]Neeraj Kumar[/eluser]
I also had same problem, I used to specify the url manually, which is not a good idea.

btw, you can use base_url function in your view files also. you don't have to pass it to the views everytime Wink
#5

[eluser]jdfwarrior[/eluser]
If this code:

Code:
function BuyRecord(id)
{
    $(”#cart”).load(”<?php echo $base;?>ajax/ajax_cart.php”, { ‘recordid’:[id] });
}

Is in an external js file, then its not executing the php. So your are literally trying to load the string you have there.. not the value of $base.
#6

[eluser]piranha_swe[/eluser]
Its not located in a js file. Its in the view file.

I tried specifying the URL too, but didnt get that to work either Sad.
#7

[eluser]jdfwarrior[/eluser]
[quote author="piranha_swe" date="1250621580"]Its not located in a js file. Its in the view file.

I tried specifying the URL too, but didnt get that to work either Sad.[/quote]

Load works fine. I have never attempted to make new functions like that within jQuery, but it doesnt seem to be working that way. In my test when I attempted to just create a new function like that within jQuery, the function was executed automatically at the document.ready event. Basically, I think you may have to extend the jquery core to create that function. Read the jQuery.extend method doc under the jQuery Core section. You may have to do it that way if you want to create the function.

When are you calling this function? Why not just, instead of making it a function, just take your code and attach it to an object.event and let it execute normally?
#8

[eluser]piranha_swe[/eluser]
I got it working now. Had forgotten to edit my .htaccess file to allow another folder.

snake: I doing it with specified url lite this: <?php echo $base;?>ajax/ajax_cart.php.
Is that a problem? Or do you mean that you tried http://www.site.com/asdf/asdf.php ?
#9

[eluser]jdfwarrior[/eluser]
Snake just meant that you didnt have to set base_url() as a variable and pass it to the view, that the base_url() function can be used within the view file. Basically, he's saying you dont have to set $base, that you could have just done:

Code:
$(”#cart”).load(”<?=base_url()?>ajax/ajax_cart.php”, { ‘recordid’:[id] });
#10

[eluser]Neeraj Kumar[/eluser]
@jdfwarrior

hmm... i think i should be more descriptive Wink

btw, just a thought came to my mind, one could create a config file for JS also and declare a base_url or something like that there so that you don't keep on fiddling up with your JS files every time.




Theme © iAndrew 2016 - Forum software by © MyBB