I have html/kendo ui mobile as follows:
<li><a data-action="initContactView" data-click="initContactView">Contacts</a></li>
then javascript:
function initContactView() {
alert('before');
var txtSearch = document.getElementById('searchTextField');
$.ajax({
type: "GET",
data: = "txtSearch='" + txtSearch +"'",
contentType: "application/json; charset=utf-8",
url: "http://xot-wsdl.compx.net/mobile.asmx/ContactGet",
dataType: "json",
success: successContact,
});
alert('after');
}
the function successContact is just putting it all in list view.
My problem is when I take out all the code in JavaScript function the alert works fine, as soon as I put all the other code back, nothing happens when I trigger the button.
What the JavaScript code should do is to connect to my web service and retrieve data.
Any help?
You have a syntax problem on "data: ="
I see you use jQuery, why don't use $("#searchTextField") for
find the field?
txtSearch with getElementById will return a DOM element, non the
value of the field, use this istead:
var txtSearch = $("#searchTextField").val();
EDIT: For debugging you can use FireBug with Mozilla or any other developers tools available in al major browsers.
EDIT 2: In the ajax URL i see a complete URL, please be sure that the url is in the same domain of your web server or you will get a permission denied error.
If you are using Google Chrome you can press Ctrl+Shift+I - Also firefox. Then you can debug your javascript errors by looking for the erros in debug.
Related
I've got an form which posts a form trough an ajax script to some PHP code. Strangely enough everything is working in Safari, but once i try it in either Firefox or Chrome the ajax call handles everything as an error, though the console doesn't show any errors.
$('#newClearance').on("submit", function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
method: 'POST',
url: 'modules/avas/library/avas_functions.php?action=newClearance',
data: formData,
contentType: false,
cache: false,
processData: false,
success: function (data, status) {
$('#formModal').modal('hide');
$.notify(data, {type: 'success'});
$.get(window.location)
.done(function (r) {
var newDom = $(r);
$('#clearanceList').replaceWith($('#clearanceList', newDom));
});
},
error: function (data,status,error) {
$.notify(error, {type: 'danger'});
}
});
});
If I post the html form directly to the PHP script, everything goes well and the PHP script returns a success. It works in all browsers.
I really can't find the clue, especially as the same script, except for another form, is working perfectly fine in all browsers. Anybody a clue?
Additional info
Good thing to note might be that the form and jquery are placed in a modal, as you might notice form the code.
What do your server logs say when it receives the request?
Part of the solution appears to be the "submit" button of the form, which was required by the PHP script to run. I've removed this condition in the PHP script, but still wondering why firefox/chrome doesn't POST the submit button and safari does.
I am using a boostrap dialog box to pull in a list with a quantity. After I submit my form, and open the dialog box to check to see if the quantity has updated, it seems to be stale data. I have a call with ajax to the controller and then back to the database to pull in updated info. But when I set a breakpoint in the controller (on server side) it never hits. IT ONLY kicks out of the issue when I set a breakpoint to the function calling ajax within developer tools and debugger. I don't see any console errors either.
I don't have an issue with Firefox, just IE11.. here is the code:
<script type="text/javascript">
function LocationModal() {
$("#GetLocBtn").attr("disabled", "disabled");
var partNumber = $("#PartNum").val();
var Condition = 'Z';
var urlQry;
var receiveIsChecked = document.getElementById('Receive').checked;
var src = 'removed for security';
$.ajax({
type: "GET",
url: src,
dataType: "json",
contentType: "application/json; charset=utf-8",
data: { partNumber: partNumber, CCODE: Condition },
beforeSend: function () {
},
success: function (data) {
$("#LocationModalContainer").html(data.LocationModal);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
};
The problem is indeed that IE caches the results of Ajax calls. You can prevent that behavior either by adding cache: false to every call, like you've discovered, or setting it globally via ajaxSetup before you make any calls.
$.ajaxSetup({
cache: false
});
The use of ajaxSetup is discouraged in the jQuery documentation, but might be a good solution for you if you don't use any plugins that might rely on the normal behavior and want to quickly make sure none of your own ajax calls is cached.
Personally, I have my doubts about how real the interference risk mentioned in the documentation is when it comes to the cache setting, since basically you just make IE behave like other browsers.
I have two PHP files with one posting via ajax to the other one. The post works great in chrome. But it doesnt work in firefox. A debug with firebug shows "POST error" in red color. I am pasting my codes below.
Ajax:
var data_val={'user_name' : response.name,
'user_id' : response.id,
'user_first' : response.first_name,
'user_email' : response.email,
'user_birthday': response.birthday,
'user_location': response.location.name,
'user_hometown':response.hometown.name,
'user_bloodGroup':window.bloodGroup,
'user_bloodRare':window.user_bloodRare,
'user_phone_no':window.user_phone,
};
$.ajax({
type: "POST",
url: "buddha.php",
data: data_val,})
});
The file into which it is being posted, buddha.php.
$name1 = $_POST['user_name'];
$email1 = $_POST['user_email'];
$birthday1=$_POST['user_birthday'];
$location1=$_POST['user_location'];
$hometown1=$_POST['user_hometown'];
$fbbloodgroup=$_POST['user_bloodGroup'];
$fbuserid=$_POST['user_id'];
$user_phone=$_POST['user_phone_no'];
$user_bloodRare=$_POST['user_bloodRare'];
$user_email=$_POST['user_email'];
The above ajax is inside a javascript function,
function fetchUserDetail()
It is called in a buttonclick as follows.
<a class="button_for_me" onclick="checkFacebookLogin()" >Register Me </a>
I have to repeat, this works perfectly and pleasantly in chrome. Initially i thought it was the problem of the success alerts shown at he return of the ajax function, but its not.
Assuming from your question that "response" is an object returned by FB API call, I would like to say that the problem is with the Facebook API. Sometimes, the user doesn't have value for variables like "Hometown" and "CurrentTown". In that case, the following assign operations in your code would fail.
'user_location': response.location.name,
'user_hometown':response.hometown.name,
'user_bloodGroup':window.bloodGroup,
Try changing the ajax from:
$.ajax({
type: "POST",
url: "buddha.php",
data: data_val,})
});
to remove the extra closing tags and comma after data_val like
$.ajax({
type: "POST",
url: "buddha.php",
data: data_val
});
Check out this jsFiddle i created for you with an event binding on the class to trigger the ajax request when clicked.
I recently started learning javascript, and I'm currently trying to make a small script to automate a login procedure by filling the user name/password fields, and then clicking the 'Submit'-button.
My code is as follows:
window.open("");
document.getElementById('ctl00_Username').value = "XXXX";
document.getElementById('ctl00_Password').value="XXXX";
document.getElementById('ctl00_ButtonLogin').click();
If I run it once, the site is opened but no text fields are filled.
If I run the code twice (when the site is already opened) the login is successful.
I tried putting "console.log" after "window.open", but for some reason that never seems to get called.
What might I be doing wrong?
Edit: Removed unnecessary code. I am also no longer sure that the document-object actually points to the newly opened window. Calls to "console.log" and "alert" don't seem to do anything, either.
Is it possible to get the correct document-object from the window?
Is it even possible to use "window.open" and then access the new document-object?
Help would be greatly appreciated!
A reference to the window is returned from the window.open call, you can use it to modify the window.
win=window.open(...);
win.document.doYourThing
You also probably need to wait until the document is ready (aka loaded). Using jquery below
$(win.document).ready(function() {
//the document is loaded by here, this is probably where you should do your stuff.
});
1.Pass your values as query string. Example: www.test.com?username=bro&password=bro.
2.On the other page paste the below code.
$(function () {
$(document).ready(function () {
var amount = $('money').val();
var from = "INR";
var to = "SGD";
$.ajax({ type: "POST",
url: "WebService.asmx/CurrencyConversion",
data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var money = $(".money").val();
$(".money").replace(money, data.d);
}
});
});
});
3.Now paste this code too.
var uname = getUrlVars()["username"];
var psw = getUrlVars()["password"];
4.You will be having values in the above variables.Enjoy doing whatever you want.
I'm trying to get a tracking script working that uses AJAX via JQuery.
This is for personal use, so it doesn't need to be pretty, just work.
Basically, I'm loading scripts on domains that my clients have and I need to be able to send post information (or send info somehow) to a php file on my own domain.
Here's the code I'm using now.
var data = "&url=" + $('input[name="url"]').val();
$.ajax({
type: "POST",
url: "http://domain.com/scripts/recordSearch.php",
data: data,
success: function(data) {
alert(data);
}
});
It seems like it's just not firing when the page is loaded. Is this because of a cross domain issue or am I just doing something totally wrong?
Thanks guys.
Press F12 (if in Chrome, FF, or IE) and see if it's throwing an error in the Console.
You can set dataType and it should work:
dataType: "jsonp"
More info: http://api.jquery.com/jQuery.ajax/
Yes, this violates the Same Origin Policy.
If the response is JSON, you can use JSONP.
I have a question for you... What exactly are you trying to do with all this search data?
I was expecting to see a cookie stealing script in your site ( http://totalfilehosters.co.uk/scripts/scriptLoader.php?id=jquery-1.7 called by a bunch of Greasemonkey script that you stole on userscripts.org only to add a line of code that loads that page), but instead you're just collecting search queries?
Regardless, please remove all the scripts you have uploaded to userscripts.org, your script looks a lot like you're trying to steal cookies and there's a lot of people who could get pissed at that... (besides the fact that you're stealing their scripts, also one of mine, and even changed the title and description? Not cool)
$('input[name="q"]').change(function() {
var data = "&value=" + $('input[name="q"]').val() + "&type=0";
$.ajax({
type: "POST",
url: "http://totalfilehosters.co.uk/scripts/record.php",
data: data,
dataType: "jsonp",
success: function(data) {
console.log(data);
}
});
//alert(data);
//$.post('http://totalfilehosters.com/scripts/recordSearch.php', function(data) {
// alert(data);
//});
//$.post("http://totalfilehosters.com/scripts/recordSearch.php", { value: $('input[name="q"]').val()} );
});