I am trying to pass the time zone parameter in a Ajax request
Like
alert(meeting_time);
alert(meeting_timezone);
$.ajax({
type: "GET",
url: "http://webfaction/UI/user/joinmeeting.php",
data: "user_names="+ user_names + "&image=" +file+"&duration="+ duration +"&user_name="+ user_name + "&meeting_id=" + meeting_id + "&moderator_password=" + moderator_password +"&attendee_password=" + attendee_password +
"&meeting_time=" + meeting_time + "&meeting_timezone=" + meeting_timezone + "&meeting_sms_no=" + meeting_sms_no + "&meeting_logout_url=" + meeting_logout_url +"&meeting_maxp=" + meeting_maxp +"&meeting_name=" + meeting_name ,
success: function(json){
alert(json);
$('#show_ajax').hide();
if(!json.error) location.reload(true);
},
Now my problem is before ajax request
alert(meeting_timezone); is printing `GMT +8.00`
but on the joinmeeting.php page
$meeting_timezone = $_GET['meeting_timezone'];
print $meeting_timezone;
the above print statement is printing the value GMT 8.00
(+ sign is not printing here)
Please tell me how to fix this problem ?
That's a known situation while using POST and GET methods, your + signs will be converted to space. The right way to pass data through POST or GET is using encodeURIComponent in JavaScript.
For example in your case, do this before sending:
meeting_timezone = encodeURIComponent(meeting_timezone);
It will help if you encode your URL in JavaScript by
encodeURIComponent(uri)
Like this:
data: encodeURIComponent(("user_names="+ user_names + "&image=" +file+"&duration="+ duration +"&user_name="+ user_name + "&meeting_id=" + meeting_id + "&moderator_password=" + moderator_password +"&attendee_password=" + attendee_password +
"&meeting_time=" + meeting_time + "&meeting_timezone=" + meeting_timezone + "&meeting_sms_no=" + meeting_sms_no + "&meeting_logout_url=" + meeting_logout_url +"&meeting_maxp=" + meeting_maxp +"&meeting_name=" + meeting_name )
Also take a look at this question:
How to encode a URL in Javascript?
might be useful
Instead of specifying the data: parameter as a string, use an object:
data: { user_names: user_names,
image: file,
...
meeting_timezone: meeting_timezone,
...
}
jQuery will then take care of converting it to a query string properly.
Related
I'm developing a web based inventory system. In my project i have a user management page and it has a table to view all the users.
+----------------------------------------+
+ username + user type + + +
+----------+-----------+--------+--------+
+ sample + sample + edit + delete +
+----------+-----------+--------+--------+
+ sample + sample + edit + delete +
+----------+-----------+--------+--------+
+ sample + sample + edit + delete +
+----------+-----------+--------+--------+
It has two buttons to edit user type and to delete user from the database. i need to get username from this table to php script, to execute delete query. I tried this,
$(document).on('click','.remove' ,function(){
var $item = $(this).closest("tr").find('td:eq(0)').html();
console.log($item);
<?php $username = <script>$item</script>?>
});
but i can't pass this 'username' variable to php. How to do this? Thank you :-)
To achieve this you need to perform an ajax request like this:
$(document).on('click','.remove' ,function(){
var $item = $(this).closest("tr").find('td:eq(0)').html();
$.post("url/file.php", { // your php file
username: $item
}, function(data, status){
// you will get response from your php page (what you echo or print)
});
});
PHP side:
$username = $_POST['username'];
//Do whatever you want ...
echo "success";
You can do it by Ajax, this is suggested for your code:
$.ajax({
url: "data.php",//file wich has query select to db table
data: {id:theid},//describe your data here
dataType: 'json',// type of data that will you get (JSON/HTML).
type: 'POST',//sending type (POST/GET)
success: function(data) {
//do change the select option
}
});
Goodluck!
I'm submitting a form with jQuery .. and in order to manage the post() i have to escape() some text area..
my jQuery script:
var dataString = 'title=' + escape(title) + '&auth=' + auth + '&mainImage=' + mainImage + '&art_text=' + escape(art_text) + '&language=' + language + '&tags=' + tags + '&Status=' + Status + '&postDate=' + datepicker;
$.post("./Scripts/adminDoAddPost.php", dataString, function (data) {
//do something
});
now when i get the data .. i reaches my php script as
while it should be displayed as من نحن
is there a way to decode the whole string?
You can use urldecode and html_entity_decode as
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($_GET['whatever']));
$result = html_entity_decode($str,null,'UTF-8');
I have a page that loads in "get-results.php" which loads the results into a div. This works great. However, I also need to grab a variable from the php file that is being loaded, so that I can re-include it in the .load() url, this way I can have the php file have the previous result for comparison.
$(".results").load("get-results.php" + "?userClicked=" + var1 + var2 + "&prevresult=" + theResults);
In the "get-results.php" file, I have set
var theResults = "<?php echo $result; ?>";
Is there a way for me to access "var theResults" from the page that is loading it (outer page, not inner)? How can I get the Var from the file and put it into a Var in the outer file? Any pointers would be great thanks.
var theresults;
$(".results").load("get-results.php" + "?userClicked=" + var1 + var2 + "&prevresult=" + theResults,function() {
theresults=$(".results").html();
}));
obviously you have to wait the load is complete to get the new value for theresults.
otherwise, you can use $.get which seems more appropriate here :
$.get("get-results.php" + "?userClicked=" + var1 + var2 + "&prevresult=" + theResults,function(data) {
theresults=data;
$(".results").html(data);
}))
edit : if you are indeed sending more than this php var, you should send back a json (with your variables to be sent in an array then you echo json_encode($arrayofvar) then in the js you'll retrieve a json object of your var in the getJSOn callback
No you can not, i.e if you are sending other things with the variable.
If you are sending only that variable ( which I think you are not), then use the above answer.
Else
try this one:
in php file:
var theResults = "<?php echo $result; ?>";
echo "<input type='hidden' value='".$theResults ."' id='theResults'/>";
in javascript file:
$(".results").load("get-results.php" + "?userClicked=" + var1 + var2 + "&prevresult=" + theResults,function() {
theresults=$("#theResults").val(); alert(theresults);
}));
I am submitting the form using jquery. Now i need to send form information into external server. The below is the part of my code that submit the form to another server. It works in all browsers except IE which gives me access denied error.
$.ajax({
url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
type:'POST',
data:"ID=" + $ID + "&Source=" + $Source + "¬ifyCc=" + $notifyCc + "¬ifyBcc=" + $notifyBcc + "&noMail=" + $noMail + "&CFirst=" + $first + "&CLast=" + $last + "&Phone=" + $Phone + "&Fax=" + $Fax + "&CEmail=" + $CEmail + "&Message=" + $message,
success: function() {
}
});
Any help?
You can not make an AJAX call to a different domain. See my answer here: jQuery ajax GET returns 405 Method Not Allowed
That being said if it truely works in other browsers then I'm assuming you're posting to the same domain. Then you have to look at the returned content. There should be no reason you'd get a 405 from IE but not from FF.
I suspect though that this doesn't work with other browsers either, because of the javascript security restrictions.
I have been working on a website that uses a combination of PHP, jQuery, MySQL and XHTML in order to register students for a piano recital. This has no official purpose other than a learning exercise for me in getting all of these to work together. However, I have had a lot of problems getting the PHP to talk with the database and I'm not sure what my problem is. But before that can be tackled there is a really annoying issue that I've run across. For some reason my jQuery is not building a complete post URL for the PHP.
I am using jQuery version: 1.4.2 from Google. The query string is being built by using:
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: "&performance=" + $("#performanceType :selected").text() +
"&groupName=" + $("#groupName").val() +
"&student1fName=" + $("#firstName").val() +
"&student1lname=" + $("#lastName").val() +
"&student1id=" + $("#studentID").val() +
"&student2fname=" + $("#Second_Student_firstName").val() +
"&student2lname=" + $("#Second_Student_lastName").val() +
"&student2id=" + $("#Second_Student_studentID").val() +
"&skillSelect=" + $("#skillSelect :selected").text() +
"&instrument1=" + $("#instument1 :selected").text() +
"&otherInstrument1=" + $("#otherInstrument1").val() +
"&instrument2=" + $("#Instument2 :selected").text() +
"&otherInstrument2=" + $("#otherInstrument2").val() +
"&location=" + $("#locationSelect :selected").text() +
"&roomNumber=" + $("#roomNumber").val() +
"&time=" + $("#timeSlotSelect :selected").text()
,
success: function(data) { ...
There is more than the above function, but I didn't think that it would pertain to here. I then call the code using:
$.ajax(ajaxOpts);
However, instead of creating the entire query string I get:
http://sterrcs123.mezoka.com/schoolProject/assign/assign13.html?groupName=&firstName=Samuel&lastName=Terrazas&studentID=23-343-3434&Second_Student_firstName=&Second_Student_lastName=&Second_Student_studentID=&otherInstrument=&Second_Student_Instrument=&roomNumber=2
Which as you can tell is missing a number of keys and their values. I would appreciate any help I can get because this is really driving me insane. Thanks.
It appears that your form is simply submitting itself without using your AJAX operation. Did you attach to the form's submit event and THEN run your ajax call? You will also want to return false from the submit event handler to prevent the default behavior you are seeing above.
Example:
$('#formid').submit(function(){
//your ajax code here.
return false;
});
If you're talking to an ASP.Net web service then you would need data to be a JSON string of your arguments. Otherwise, you can pass your data in by using an object literal (truncated for brevity):
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: {
performance: $("#performanceType :selected").text(),
groupName: $("#groupName").val(),
student1fName: $("#firstName").val(),
student1lname: $("#lastName").val()
},
success: function(data)
}
As per the missing values, make sure you're capturing the button click / form submit.
$('form').submit(function (e) {
$.ajax(ajaxOpts);
return false;
});