-1

i am working with javascript jquery. I m sending request to the url for getting json response and i want that json response should be displayed in another html page with some good format may be in table or smoother format.then how can i do that.and also i want to update data in my html page depending upon the json response dynamically.so how can i do that.and am working with phonegap then which technology should i use for server side ?

$.ajax({
    type: "GET",
    url: "url",
    data: null,
    contentType: "application/json; charset=utf-8",
    success: function(data) {
        alert("success");
    }
}, error: function(jqXHR, exception) {
    if (jqXHR.status === 0) {
        alert('Not connect.\n Verify Network.');
    } else if (exception === 'timeout') {
        alert('Time out error.');
    } else if (exception === 'abort') {
        alert('Ajax request aborted.');
    } else {
        alert('Uncaught Error.\n' + jqXHR.responseText);
    }
}
});  
Nurdin
  • 23,382
  • 43
  • 130
  • 308
user3415421
  • 215
  • 1
  • 2
  • 14

2 Answers2

0

replace with this code

$.ajax({
    type: "GET",
    url: "url",
    data: null,
    contentType: "application/json; charset=utf-8",
    success: function(data) {
        alert("success");
    },
    error: function(jqXHR, exception) {
        if (jqXHR.status === 0) {
            alert('Not connect.\n Verify Network.');
        } else if (exception === 'timeout') {
            alert('Time out error.');
        } else if (exception === 'abort') {
            alert('Ajax request aborted.');
        } else {
            alert('Uncaught Error.\n' + jqXHR.responseText);
        }
    }
});
Nurdin
  • 23,382
  • 43
  • 130
  • 308
-1

Rather than the alert("sucess") you could use some code like this

myDiv = document.getElementById('htmldiv');

myDiv.innerHTML = "Success";

But basically just dynamically update part of your page. You could also display the responce see below, the result of that will depend on what is the results of the AJAX call.

myDiv.innerHTML = jqXHR.responseText;

  • i know this way..i am getting that response also but in my one form i m getting the list of merchant in json format by get method and i want to display that list in some other html page in table format and this list is changing everytime from server so whatever change is there it should be updated in that html table..how can i do this..? – user3415421 Mar 21 '14 at 11:24
  • What is the issue ? Converting JSON to a dynamic HTML Table OR the communication between Web pages ? – Flying Scotsman Mar 21 '14 at 11:29
  • converting json to dynamic html table..how can i append the data so that it should be displayed in html page.? – user3415421 Mar 21 '14 at 11:33
  • I would parse the JSON and then use document.createElement to create required HTML then appendChild to add the HTML created into the page. – Flying Scotsman Mar 21 '14 at 12:11
  • can u give me some link for this to get this information..? – user3415421 Mar 21 '14 at 12:17
  • Here are a couple of link to something similar http://stackoverflow.com/questions/16209318/parse-json-string-to-html-divs-using-jquery http://stackoverflow.com/questions/22505712/cross-domain-json-parse-to-display-in-html-using-jquery-error Hope this helps... – Flying Scotsman Mar 21 '14 at 12:43