I am trying to get the value i am sending from one page to another using jquery ajax json.
This is my code:
function checkTheVin()
{
$.ajax({
type: "POST",
url: "checkVin.asp",
data: 'theVIN=' + $("#vwVin").val(),
cache: false,
dataType: "html",
beforeSend: function() {$.blockUI({ message: '<img src="img/ajax-loader.gif" />' });},
complete: function(){$.unblockUI();},
success: function(responseText){
if (responseText.indexOf("GOOD") > -1)
{
$("#theContent").html(responseText.replace("GOOD",""));
}else{
//alert(data);
}
},
error: function(responseText){alert('err: ' + responseText);},
});
}
However i never get a resonse back. It's null.
This is how i am getting it using CLASSIC asp:
dim vwVin
vwVin = request.QueryString("theVIN")
What am i doing incorrect?
David
Try using a GET method in your ajax call:
$.ajax({
type: "GET",
url: "checkVin.asp",
data: 'theVIN=' + $("#vwVin").val(),
cache: false,
dataType: "html",
beforeSend: function() {$.blockUI({ message: '<img src="img/ajax-loader.gif" />' });},
complete: function(){$.unblockUI();},
success: function(responseText){
if (responseText.indexOf("GOOD") > -1)
{
$("#theContent").html(responseText.replace("GOOD",""));
}else{
//alert(data);
}
},
error: function(responseText){alert('err: ' + responseText);},
});
You have three options
1. Use the Request Object with out specifying the collection
dim vwVin
vwVin = request("theVIN")
The web server will then search request collections for you, first the querystring and then the form.
2. Specify the Request.Form collection if you are using Ajax Post
$.ajax({ type: "POST", ...
dim vwVin
vwVin = Request.Form("theVIN")
3. Specify the Request.QueryString collection if you are using Ajax GET
$.ajax({ type: "GET", ...
dim vwVin
vwVin = Request.QueryString ("theVIN")
Related
I am trying to pass parameter in below ajax url
function endprogress(){
$("#surfbar").html("Please wait...");
var dataString = 'action=validate&t='+adtk;
$.ajax({
type: "POST",
url: 'yes_manage.php?view=surf&track='+user_name&, /*this line giving error*/
data: dataString,
success: function(msg){
}
});
}
above url field is giving error Expected and identifier instead saw ','
how can I resolve this
Change user_name& => user_name
look like
function endprogress(){
$("#surfbar").html("Please wait...");
var dataString = 'action=validate&t='+adtk;
$.ajax({
type: "POST",
url: 'yes_manage.php?view=surf&track='+user_name, /*remove & at the end user_name*/
data: dataString,
success: function(msg){
}
});
}
When I use the code below, paging is not working. Where am I wrong?
var data = '';
$.ajax({ type: "GET",
url: "include/tables/data.php",
async: false,
success: function(data) {
$("#result").html(data);
$('#mytable').DataTable({});
}
});
My Ajax call is really simple as below:
function ajax(reqUrl, params , callback) {
console.log("Request URL "+reqUrl);
var cond;
cond = $.ajax({
type: 'post',
url: reqUrl,
data: params,
error:function(){ alert("some error occurred") },
success: callback
});
console.log("Server response "+cond.readyState);
}
// Call it as
var url = "/getResult";
var params = {};
params.param1 = "test1";
params.param2 = "test2";
ajax(url, params, function(returnCallback) {
console.log(returnCallback);
alert("Success");
});
That works fine in most cases. But sometimes (about 1 times in 3) it doesn't return anything to callback.
I found many questions and answers for Not working ajax in Safari but fine in chrome and FireFox. My problem is different from them, because it's fine most of the time (I don't mean it was not fine usually because when I refresh my browser, that may cause my ajax call to work).
My main question is why does my ajax call sometimes fail? I don't get any errors on my JS console. When this situation, I refresh my browser to get my ajax call to. Any Ideas?
Update:
I found that sometimes my ajax call method didn't call out because console.log("Request URL "+reqUrl); did not execute. When I don't want to refresh my browser, I clicked many times on my page's link to produce result. will something late to execute?
Finally, I found error .. Safari doesn't reload my JavaScript files again even disable Cache. So I put all of my JS code into:
$(document).ready(function(){
// start load my js functions
init();
});
to reload my JS files when my page was ready. Cheer !
I also met this problem.
When I moved all code into $(function() {}), it worked.
After that, I found I had defined a variable named key, which caused the problem.
Just rename it, all things will be running.
This seems to be a Safari issue. In this post there is a suggestion to add a beforeSend to your ajax-request.
In your case:
cond = $.ajax({
type: 'post',
url: reqUrl,
data: params,
beforeSend: function (event, files, index, xhr, handler, callBack) {
$.ajax({
async: false,
url: 'closeconnection.php' // add path
});
},
error:function(){ alert("some error occurred") },
success: callback
});
Please Test below Code. it is working fine.
$.ajax({
type: "POST",
url:'#Url.Action("getResult","Controller")',
data: "{userName :'" + userName + "',password :'" + password + "' }",
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (data) {
alert("here" + data.toString());
});
This is use for MVC application.
$.ajax({
type: "POST",
url:'getResult',
data: "{userName :'" + userName + "',password :'" + password + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("here" + data.toString());
});
For Asp.net Application :
$.ajax({
type: "POST",
url:'getResult',
data: "{userName :'" + userName + "',password :'" + password + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("here" + data.toString());
});
if u have still the issue than please post ur complete code here. i will test and reply soon
I have the below that uploads an image using JQuery's AJAX function
var id = <?php echo $id; ?>;
var img_data = new FormData($("form")[0]);
$.ajax({
url: 'add.php',
data: img_data,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}
});
I'd like to include a string with the FormData sent. I tried the following, but no luck
data: img_data {id: id},
What's the correct syntax here?
Use append
var img_data = new FormData($("form")[0]);
img_data.append('id', id);
You could create a JSON data object and pass that as application/json and process the data within add.php:
var data = {
id : <?php echo !empty($id) ? $id : "''",
img_data : new FormData($("form")[0])
};
$.ajax({
url: 'add.php',
data: data,
contentType: "application/json",
type: 'POST',
success: function(data){
alert(data);
}
});
Although unconventional, you could also append the data as a query string to the URL with the POST. You'd also need to edit add.php to get this parameter.
$.ajax({
url: 'add.php?id=' + id,
data: img_data,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}
});
I am trying to send some information to my php page via an ajax call. However I am getting an issue that a } missing after property list. Below is my code:
function article(Article){
var surl = "http://www.webapp-testing.com/includes/article_desc.php";
var id = 1;
$.ajax({
type: "POST",
url: surl,
data: '"Article="+Article';
dataType: "jsonp",
cache : false,
jsonp : "onJSONPLoad",
jsonpCallback: "articlecallback",
crossDomain: "true",
success: function(response) {
alert("Success");
},
error: function (xhr, status) {
alert('Unknown error ' + status);
}
});
}
Any help will be greatly appreciated
Change the ; after your data attribute to a ,.
data: '"Article="+Article',
This string should end with ,:
data: '"Article="+Article';
You have a semicolon after the "data" element. It should be a comma.
replace the the semicolon on line data: '"Article="+Article'; with ,