Phonegap Ajax Post to PHP live server not posting through IOS - html

I see there are several posts on this issue, however none of the answers are very clear or are working for me. I have a simple JQuery Post that works great in a browser, but doesn't post to the PHP page on the server through the native app on IOS. Is there a handler I can add to make it work or is it a whitelist issue? Either way is there a good resource or simple instructions to fix the issue? See my code below.
$(function() {
$('#RFQ, #sQuote, #sQuote1, #sQuote2, #sQuote3').submit(function() {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(data) {
$('#RFQ, #sQuote, #sQuote1, #sQuote2, #sQuote3').html( $("#formResponse").html() );
}
});
return false;
});
});

Make sure you modified your file Cordova.plist correctly to allow external access.
Open your file Cordova.plist and check that you made the following:
1 - Set OpenAllWhitelistURLsInWebView to YES
2 - Right click on ExternalHosts -> Add Row
3 - Set the String value of your new added row to *, so you should have your new line look like this:
Item0 String *
Normally, you would replace * with the external URL you want provide access to. But, to make sure that the problem really comes from the whitelist, we will use *.
For more information about domain whitelist, check the online doc: http://docs.phonegap.com/en/2.1.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide
Hope this helps.
Let me know if this works for after modifying your Cordova.plist file as described above.

Related

How can I include a hyperlink as a parameter in Express?

I'm trying to send a hyperlink (such as: "http://google.com") as a parameter to my Express server script. My current script looks like this:
var app = require("express")();
app.get("/new/:link(*)", function(req, res){
var link = req.params.link;
res.end(JSON.stringify({
site: link
}));
});
app.listen(process.env.PORT || 3000, function(){
console.log("Listening...");
});
This is just a test to see if I can get it working so I can build something bigger on top. The idea is that I can send a link and receive the link in JSON. However when I try to go to the site with the the link as parameter, my browser want to save a file called "google.com" and it doesn't receive any JSON from the server.
I know it's possible to do this without changing anything about my browser but I don't know how. Anyone has any ideas?
Ok, so I have accidentally fixed my problem.
Apparently i had to write "res.send(...)" instead of "end". It now works perfectly although I don't really understand why.

JSON response from URL

Hey I'm trying to retrieve data from a json file I have hosted on my server but it's not working, I'm not sure what is wrong as I'm not the most well versed in this topic. Any tips are appreciated!
$(document).ready(function () {
$("#button").click(function () {
$.getJSON({
type: "POST",
url: "some URL will go here",
success: function (result) {
$("#div1").append(result);
}
});
});
});
heres the fiddle as well: http://jsfiddle.net/ahuston12/E5SzH/
Open a modern browser like Firefox or chrome and open the developer tools. Navigate to the page that contains the above code and monitor the "network" tab to see the related http request triggered via ajax. You can then see the request + response including header, body and return codes. This should help to figure out the problem.
You should show us what's going on the server side.
It doesn't seems to be problems on this jquery code so i guess it's from server.
You can check the response value to see the problem :
on chrome ctrl+j -> network. You'll see your request, click on it to see details like the server's response.
If you have FireBug installed in your Mozilla Firefox open it, in that you can see Net Tab . If you click that you can able to see what kind of response you are getting. I ahve attached the Image For your reference. And for getting a JSON result use "result.d".
The url that you are using doesn't return a json response, it returns a javascript file that charge a json result into a variable, because of that you can't get the result.. if you try with other site that returns information in json format like this you are going to get the data:
$.getJSON("http://headers.jsontest.com/", function (result) {
console.log(result);
}
);

Ajax auto update when db updated

I need my text to auto update when the mySQL database is updated.
Could someone please help with this? I've looked a lot and no post says what I need, i'm new to ajax and don't know much about it. All I know is HTML, CSS, PHP and javascript.
First of all, you might wanna check jQuery. It'll be very simple if you know javascript, and it'll make your development a lot easier.
Then you need to check how an ajax call is implemented with jQuery. Again, really simple, here's an example.
test.php
$var1 = $_POST['key'];
$var2 = $_POST['key1'];
//Some code here
echo 'Test finished'; // This is returned to the ajax call
JAVASCRIPT
$.ajax({
url: '/test.php',
type: 'POST', /*Method, POST or GET depending on your needs*/
async: true, /*This makes the ajax call asyncronously or not*/
data: {'key':value,'key2':value2},/*data to send*/
success: function(result){ /*Return from PHP side*/
/* result contains the data replied from the PHP script. */
alert(result);
}
});
If you want to replace some parts of your HTML you might wanna check functions like, append, after, before, prepend and html,etc. Also learn something about JSON, it's a data format. Really simple and yet magnificent
Hope this helps you! It looks like homework, but you'll ace it in no time, you'll see.

Mootools Request to change javascript code?

So I am planning on dynamically changing a page's content by fetching it from another page.
To do so, I used Mootools' Request class:
var tabContent = new Request({
url: 'foo/bar/baz.php',
onSuccess: function(data) {
$('tab_container').innerHTML = data;
}
}).send();
In any case, the HTML is fetched fine, and returns without a hitch. However, I'd like to add some events to THOSE fetched elements (Fx.slide, to be precise), and that requires some js to be included in the requested file.
Upon inspection of the returned data, the javascript is intact. However, it does not show up in the final product. That is, somewhere in between having received the data, and rendering the data (via the innerHTML bit) it seems as though the javascript has been excised out for some reason.
Hm.
add evalScripts: true to the Request options, then include the script in a simple <script></script> block at the bottom of the response.

$.ajax misfire in ie6

I'm using the flickr api to create a simple gallery based on images pulled in by their tag.
The gallery is working fine in every browser except ie6. When you navigate to the page (by clicking a link) in ie6, the $.ajax success/error code blocks refuse to fire, however when the page is reloaded, or navigated to directly (by entering a url) there are no problems.
$.ajax({
type: "GET",
url: "http://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=" + api_key + "&user_id=" + user_id + "&tags=" + tags + "&format=json&jsoncallback=?",
cache: false,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert('good');
},
timeout: 2000,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
The above code is obviously a simplified version of the actual javascript, but the bug is still present.
Any help would be greatly appreciated. This seems to be a very weird bug. Perhaps it's a caching issue?
This problem is pretty recurrent. IE caches AJAX calls. You need to append a random number or string to your call each time so that it doesn't run a cached call.
url: "http://[your url]&rand=" + Math.Random(),
Two thoughts:
Is your call within a
$(document).ready() block?
Try getting rid of the ampersand
right at the beginning of the query
string:
/?method=flickr.photos.search&...
How is the "link" triggering the AJAX load?
inline onclick="doSomething();"
inline href="javascript:doSomething();"
via jQuery $('#somelink').bind('click', doSomething);
something else?
I ask because IE6 has a known bug whereby if you have/use the javascript: protocol on a link... then use JavaScript to load a different page it requests the page but never renders it. I wonder if (depending on how your AJAX is attached) if the above bug extends to AJAX requests not just location.href requests.
Four things related to your code but not to your question:
timeout is not taken into account by $.ajax when dealing with jsonp
nor is contentType
the error callback is never called in the context of a jsonp request
You should really use the data parameter (the code would be far cleaner than with the custom url building it currently shows)
Point 1 & 3 are due to limitations in the way $.ajax is implemented. I recommend http://code.google.com/p/jquery-jsonp/ if you really need those features.
Now, apart from what karim79 pointed out, I see nothing wrong with your code. So my guess is you have something else going wrong prior to it in the function you feed to $(document).ready(). IE is far less lenient than other browsers when it comes to javascript syntax. Try putting the $.ajax call as early as possible.
Also:
Does it work in IE7?
What version of jQuery are you using?