blueimp does not allow second post operation via jquery adapter - php

I am using blueimp in my website. blueimp is included at the end of my page(index.php) like:
<?php include "index.html"; ?>
In my php page I am also using a jquery adapter which sends some variables from the same page and two variables from blueimp uploader via:
function save()
{
var variable1= document.getElementById('field1').value;
var variable2= CKEDITOR.instances.field2.getData();
variable2=encodeURIComponent(variable2);
var variable3= document.getElementById('field3').value;
var variables="variable1="+variable1+ "&variable2="+variable2+
"&variable3="+variable3;
jQuery('#mydiv').showLoading();
$.ajax({
type: "POST",
url: "some.php",
data: variables,
error: function(){
alert('Error while loading!');
},
success: function(data){
jQuery('#mydiv').hideLoading();
$('#mydiv').html(data);
}
});
}
Whenever I call this function the variables are not sent to some.php . However if I remove
<?php include "index.html"; ?>
from index.php page, the function save starts to work. I guess something from included blueimp page ,which is index.html, prevents the jquery adapter to function properly.
Is there any clue on this issue?
Thanks in advance.

It sounds like you are having some conflicts between the two libraries. jQuery has this option called noConflict() to allow you to sort of 'pause' jQuery for a bit and allow other libraries to work and then 'resume' normal jQuery functions.

Related

Can I dynamically load a portion of a table first?

I've recently changed my searching page to a searchable datatable page due to my employer's request for easier data management. The problem is that it is taking too long to load.
I'm wondering it there is a way to only load like a portion of the table and finish loading the page first. Then finish off loading the rest of the table after that, e.g. while the user actually attempt to search for the data.
This was requested because the user might want to navigate to other parts of the page instead of using the datatable.
Extra info : The page is in .php and the data is loaded using php do-while loop. Maybe we can do a workaround using php functions?
Using the AJAX method recommended in the comments, the following is similar to how you could handle the page-load. You would need the jQuery library for the below.
Initial page
<script type="text/javascript">
// when the page is done loading,
// let's send a call to load more data
$(document).ready(function(){
myFunction();
});
// function to handle AJAX request to gather data
function myFunction(){
$.ajax({
type: "POST",
url: "./linkToMyPHP.php?loadData=1",
success: function(data){
// handle the data using the "data" variable
}
});
}
</script>
AJAX Page
<?php
if(isset($_GET["loadData"])){
// call query here and echo information
}
It may be recommended, to actually use a PHP function called json_encode() to echo back the information from your AJAX page in JSON form. This would allow you to transmit an array of information, instead of raw data. You would then need to update your AJAX request function similar to below.
$.ajax({
type: "POST",
url: "./linkToMyPHP.php?loadData=1",
dataType: "json",
success: function(data){
$("#myDivToChange").html(data);
}
});
You can read up on JSON at this highly rated question.

which is the best method to move php code out of js in ajax

I am developing an application in Yii.. One issue i am facing is, when i am writing ajax functions, the url's will be in php. so i am unable to move the codes to another javascript file.
$.ajax({
url: "<?php echo Yii::app()->createUrl('provider/ajaxdetail');?>",
data: {'type':tagtype},
beforeSend: function() { },
success: function(data) {
}
});
so what is the best method to move php out of the javascript so that i can move the javascript code to another js file. I Thought of putting the url's in a hidden box and then call it in the javascript function. but i hope there will be better methods to do this .
please help
you could create a global variable to store the url, in your html head , so that any js file that needs the url can access it, like:
<html>
...
<head>
..
var MY_APP_URL = '<?php echo Yii::app()->baseUrl; ?>'; //can be like www.somesite.com/
....
//load js files
...
and in the js file you could do:
$.ajax({
url: MY_APP_URL + "controller_name/function_name",
data: {'type':tagtype},
OR you could do:
Yii::app()->clientScript->registerScript('helpers', '
someUrl = '.CJSON::encode(Yii::app()->createUrl('blabla')).';
baseUrl = '.CJSON::encode(Yii::app()->baseUrl).';
');?>
and you can use variables someUrl and baseUrl in your Javascript files

Run ajaxed javascript

I know this has been covered a few times, but I'm completely a noob when it comes to javascript so I have no idea what I'm doing. I am running a javascript that sends variables to a php file and that info is ajaxed into the current page using innerhtml. Here is that part of the code...
function givingHistory(dyear,did)
{
var divname="giving" + dyear;
$.ajax({
url: 'finance/givinghistory.php',
type: 'POST',
data: {
year: dyear,
id: did
},
success: function(givedata) {
document.getElementById(divname).innerHTML = givedata;
}
});
}
</script>
In the givedata function response from the php file there is a call to another javascript function that is already loaded in my common .js file (so both javascript functions are loaded when the page loads). How do I get the onClick that is added via innerhtml to work? Inside the php file, I check to see if id = a php session variable. If it does it spits out the text that includes the onClick.
If you use a specific id/class/identifier when the page loads in the $('*') function then the action will only bind to that. To get the action bind to anything ever try using $(document).on('click', **selector**, function() {});.
Previously there was bind/live that bound to elements as and when but on is the function now.
Also why are you mixing the $.ajax (jQuery) with document.getElementById(divname).innerHTML (regular javascript)? If you are already using jQuery you could just use $('#'+divname).html(blahbahblah);

jQuery pop up - ask for variable before loading page

I need a jQuery popup to ask the user for some required data before loading the same page it's on.
The data entered will become a php variable that I'll use to query a mysql table and pre-populate some form fields.
Any advice?
Thanks!!
you can make an AJAX call to the PHP and load it to div that you want. For the ajax calls you can use jquery it really makes you job easy.
eg:
$.ajax({
url: 'getitems.php',
success: function(data) {
$('#manage_inventory').html(data);
//alert('Load was performed.');
}
});
like in the example it is calling getitems.php and getting the list and loading it into #manage_inventory. The data being returned can be XMl or other type which can be parsed and be used according to your needs.
Your solution could be as simple as using a prompt() box in javascript and then passing the information via ajax
var stuff = prompt('Gimme Stuff');
$.ajax({
url: 'dostuff.php',
data: 'stuff=' + stuff,
success: function(data) {
//process stuff
}
});

Make an AJAX call after AJAX file uploader is complete?

I am trying to find an AJAX File uploader to use, I think i may go with this on below:
http://valums.com/ajax-upload/
The issue i am having is that i cannot figure out how to make a jQuery AJAX call when the uploader has finished uploading the file. Is this possible? I don't have to necessarily use this specific uploader.
This ajax uploader has an onComplete event callback, so you'll just have to pass your jQuery ajax call to it. Something like this:
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader'),
action: '/server/upload',
onComplete: function(id, fileName, responseJSON) {
// Here comes your jQuery ajax call
$.ajax({
url: 'ajax/post_process.php',
success: function(data) {
// ...
}
});
}
});
Hello try my beta ajax mutiple upload jquery based, simple efficient download it at: http://www.albanx.com/ . no flash, with progress, work over https, support main browsers..
you can use success function for calling the final function

Categories