简体   繁体   English

能够在phonegap中发送和接收json数据的Javascript文件

[英]Javascript Files that enable sending and receiving json data in phonegap

Which javascript files must be available either in client-side or server-side for you to be able to send and receive json data in your BlackBerry phonegap application. 您必须在客户端或服务器端都可以使用哪些JavaScript文件,才能在BlackBerry phonegap应用程序中发送和接收json数据。

I see this often omitted in all the solutions to json-related questions that have been posted. 我发现在已发布的所有与json相关的问题的解决方案中,通常都忽略了这一点。

I am completely new to phonegap and jQuery and so I need help also I am trying to send form details (like firstName and lastName) to a php file on the server-side. 我对phonegap和jQuery完全陌生,因此我也需要帮助,我也在尝试将表单详细信息(例如firstName和lastName)发送到服务器端的php文件。

So that the data would be processed by the php and the record would be stored on my database. 这样数据将由php处理并将记录存储在我的数据库中。

Can some one work me through how to send the data using json? 有人可以帮我解决如何使用json发送数据吗?

You can get detail on Json integration in phonegap from this blog . 您可以从此博客中获取有关phonegap中Json集成的详细信息。

this blog will explain through a simple example how you can use JSON to ease the client-server data transmission. 本博客将通过一个简单的示例说明如何使用JSON简化客户端-服务器数据传输。

Don't bother about server site, server team (PHP/Java) will take care of it. 不要担心服务器站点,服务器团队(PHP / Java)会照顾好它。
In phonegap app every logic is buid in javascript, so in your case if you want to send some information to server, you need to create json object and append it to $.ajax function and same function to receive the response from server: 在phonegap应用程序中,每个逻辑都是javascript中的buid,因此,如果您要向服务器发送一些信息,则需要创建json对象并将其附加到$.ajax函数和相同的函数中,以接收来自服务器的响应:

$.ajax({  
   url:'stringURL',  
   beforeSend: function(x) {      
     x.setRequestHeader('Authorization','username/pwd');  
   },  
   dataType:"json",  
   contentType:'application/json',  
   timeout:10000,  
   type:'POST', 
   data : {
     //append json data here if you want to send some data to server
   }, 
   success:function(data) {  
     alert(data); // here you will get json data on success, parse it like key-value mechanism in js 
   },  
   error:function(XMLHttpRequest,textStatus, errorThrown) {     
     alert("Error status :"+textStatus);  
     alert("Error type :"+errorThrown);  
     alert("Error message :"+XMLHttpRequest.responseXML);  
   }
});

Please have a look at this blog to write php-web service or share with you server team. 请查看此博客以编写php-web服务或与您的服务器团队共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM